poj 1322

状态转移方程还是很容易想出的,但是n的限值1000不知道为什么

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 using namespace std;
 5 const int maxn=100+10;
 6 double f[2][maxn];
 7 int c;
 8 int n,m;
 9 int main()
10 {
11     while(scanf("%d",&c)&&c)
12     {
13         scanf("%d%d",&n,&m);
14         if(m>c)//主要是为了防止RE
15         {
16             printf("0.000\n");
17             continue;
18         }
19         int i,j;
20         memset(f,0,sizeof(f));
21         f[0][0]=1.0;
22         if(n>1000) n=1000+(n&1);
23         int t=1;
24         for(i=1;i<=n;i++,t=!t)
25         {
26             f[t][0]=f[!t][1]/c;
27             for(j=1;j<=c;j++)
28                 f[t][j]=f[!t][j+1]*(j+1.0)/c+f[!t][j-1]*(c-j+1.0)/c;
29         }
30         printf("%.3lf\n",f[!t][m]);
31     }
32     return 0;
33 }
原文地址:https://www.cnblogs.com/lj030/p/3130796.html