概率DP (大概是最入门的题了) lightoj 1248

有一个骰子,n个面,问所有面都被摇出的期望。

 转自**的博客,  因为概率是(n-k)/n  所以期望次数是1/(前面这个数) 

 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<math.h>
 4 #include<string.h>
 5 using namespace std;
 6 int main()
 7 {
 8     int T;
 9     scanf("%d",&T);
10     int cnt=0;
11     while(T--){
12         int n;
13         scanf("%d",&n);
14         double ans=0.0;
15         for(int i=1;i<=n;i++)
16             ans+=1.0/i;
17         printf("Case %d: ",++cnt);
18         printf("%lf\n",ans*n);
19     }
20     return 0;
21 }

猜你喜欢

转载自www.cnblogs.com/pangbi/p/11603730.html