hdu1493 概率dp(掷色子n次到定点概率)

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define eps 1e-8
 4 int a[]={5,12,22,29,33,38,42,46,50,55};
 5 double d[15],dp[105];
 6 int main()
 7 {
 8     int T,i,j,k;
 9     scanf("%d",&T);
10     while (T--)
11     {
12         for (i=1;i<=6;i++) scanf("%lf",&d[i]);
13         for (i=0;i<=60;i++)
14             dp[i]=0.0;   dp[0]=1.0;
15         for (i=1;i<=10;i++)
16         {
17             for (j=60;j>0;j--){
18                 dp[j] = 0;
19                 for (k=1;(k<=6)&&(j>=k);k++)
20                     dp[j]+=(dp[j-k]*d[k]);
21                 }
22         }
23       for (i=0;i<10;i++)
24             printf("%d: %.1lf%%\n",a[i],(100.0*dp[a[i]]));
25         if (T) printf("\n");
26     }
27 }

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1493

posted on 2014-11-05 21:42  xiao_xin  阅读(377)  评论(0编辑  收藏  举报

导航