传送门
题意

分析
我们设
f
[
i
]
[
j
]
f[i][j]
f[i][j]表示第
i
i
i天取到
j
j
j种球的概率,然后顺着推就好
因为
f
[
i
]
[
j
]
f[i][j]
f[i][j]只和
f
[
i
−
1
]
[
k
]
f[i - 1][k]
f[i−1][k]有关,所以可以用滚动数组来优化空间
代码
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e3 + 10;
const ll mod = 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a) {
char c = getchar(); T x = 0, f = 1; while (!isdigit(c)) {if (c == '-')f = -1; c = getchar();}
while (isdigit(c)) {x = (x << 1) + (x << 3) + c - '0'; c = getchar();} a = f * x;
}
int gcd(int a, int b) {return (b > 0) ? gcd(b, a % b) : a;}
double f[N];
int n,q;
int ans[N],idx;
int main() {
int n,q;
read(n),read(q);
f[0] = 1;
for(int i = 1;idx <= 1005;i++){
for(int j = min(i,n);j;j--) f[j] = (f[j - 1] * (n - j + 1) + f[j] * j) / n;
while(i >= n && f[n] * 2000 >= idx) ans[idx++] = i;
f[0] = 0;
}
while(q--){
int x;
read(x);
di(ans[x]);
}
return 0;
}
博客主要讨论了一种概率动态规划问题的解决方案,通过滚动数组优化空间复杂度,实现快速计算每天取到特定种类球的概率。代码示例中展示了如何使用C++实现这一算法,并给出了样例输入和输出。
593

被折叠的 条评论
为什么被折叠?



