LightOJ - 1248 Dice (III)

给你一个n面的骰子 问你期望丢几次能每一面都见过

题目链接

#include <bits/stdc++.h>
#define ll long long
#define inf 0x3f3f3f3f
using namespace std;
const int N = 1e5+7;
const double eps = 1e-8;
double dp[N];
int main(){
//    ios::sync_with_stdio(false);
//    cin.tie(0);
    int t;
    scanf("%d",&t);
    int w=0;
    while(t--){
        int n; scanf("%d",&n);
        dp[n]=0;
        for(int i=n-1;i>=0;i--){
            dp[i]=((n-i)*1.0*(dp[i+1])+n)/(n-i);
        }
        printf("Case %d: %.10f\n",++w,dp[0]);
    }
}

猜你喜欢

转载自www.cnblogs.com/wmj6/p/11204050.html