码迷,mamicode.com
首页 > 其他好文 > 详细

POJ2151 动态规划

时间:2014-07-27 22:44:29      阅读:277      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   io   for   div   amp   

 1 #include <iostream>
 2 #include <cstring>
 3 #include <cstdio>
 4 
 5 using namespace std;
 6 
 7 int m, t, n;
 8 double dp[1005][40][40];
 9 double p[1005][40];
10 double p1, p2;
11 
12 int main()
13 {
14     while (scanf("%d%d%d", &m, &t, &n) && m) { //这里的&&写成了&,wa了1个小时
15         memset(dp, 0, sizeof(dp));
16         for (int i = 1; i <= t; i++) {
17             for (int j = 1; j <= m; j++) 
18                 scanf("%lf", &p[i][j]);
19         }
20 
21         for (int i = 1; i <= t; i++) {
22             
23             dp[i][0][0] = 1.0;
24             for (int j = 1; j <= m; j++) {
25                 dp[i][j][0] = dp[i][j - 1][0] * (1 - p[i][j]);
26             
27                 for (int l = 1; l <= j; l++) {
28                     dp[i][j][l] = dp[i][j - 1][l] * (1 - p[i][j]) 
29                                 + dp[i][j - 1][l - 1] * p[i][j];    
30                 }
31             }
32         }
33 
34         double s1 = 1;
35         double s2 = 1;
36         
37         for (int i = 1; i <= t; i++) {
38             p1 = 0;
39             for (int j = 1; j < n; j++) 
40                 p1 += dp[i][m][j];
41             s1 *= p1;
42         }
43 
44         
45         for (int i = 1; i <= t; i++) {
46             p2 = 1 - dp[i][m][0];
47             s2 *= p2;
48         }
49         printf("%.3lf\n", s2 - s1);
50     }
51     return 0;
52 }

 

POJ2151 动态规划,布布扣,bubuko.com

POJ2151 动态规划

标签:style   blog   color   os   io   for   div   amp   

原文地址:http://www.cnblogs.com/junxie/p/3871615.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!