题意: 给你一个n个点的色子, 掷一次色子获得每个点数的概率相同, 求得到所有点数时掷色子次数的期望值;
思路: 假设已经有k个点数已经出现过, 则掷下一次可能得到未出现过的点数, 期望为1, 也可能得到已出现过的点数, 概率为k / n, 若得到已出现的点数, 则继续掷色子, 所以期望
E = 1 + k / n (1 + k / n (1 + n / k * (...)))
= 1 + k / n + (k / n) ^ 2 + (k / n) ^ 3 + ...
= 1 + k / (n - k)
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#include<functional>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 10;
const double eps = 1e-9;
const int inf = 1 << 30;
int main() {
int t, v = 1, n;
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
double ans = 0;
for(int k = 0; k < n; k++) {
ans += 1 + 1.0 * k / (n - k);
}
printf("Case %d: %.8f\n", v++, ans);
}
return 0;
}