hdu4652 m面的筛子期望掷多少次可以使最后n次完全相同/完全不同

其实归根到底还是3853那样的分两种情况看后继点,只是递推公式和化简公式较为繁琐

我是参考别人的化简:http://blog.csdn.net/auto_ac/article/details/9919851

化出来的公式倒是很简单==

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7   int n,m,T,i,type,ans;
 8   double s,d;
 9   while (~scanf("%d",&T))
10   {
11     while (T--)
12     {
13       scanf("%d%d%d",&type,&m,&n);
14       if (type==0){
15         ans=1;
16         for (i=1;i<=n;i++) ans*=m;
17            printf("%lf\n",1.0*(ans-1)/(m-1));
18       }
19       else{
20         s=d=1.0;
21         for (i=1;i<n;i++)
22         {
23           d=1.0*m/(m-i)*d;
24           s+=d;
25         }
26         printf("%lf\n",s);
27       }
28     }
29   }
30   return 0;
31 }
View Code

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4652

posted on 2015-03-01 22:16  xiao_xin  阅读(114)  评论(0编辑  收藏  举报

导航