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

hdu 3853 写傻了的期望dp,不能正推?!!

时间:2015-02-13 23:39:44      阅读:255      评论:0      收藏:0      [点我收藏+]

标签:

//下面是错误代码...

 1 #include "iostream"
 2 #include "cstdio"
 3 #include "cstring"
 4 #include "algorithm"
 5 #include "cmath"
 6 using namespace std;
 7 const double eps = 1e-5;
 8 double dp[1010][1010];
 9 int R, C;
10 double p[1010][1010][3];
11 bool cant[1010][1010];
12 
13 int main()
14 {
15     int i, j, k;
16     while(scanf("%d%d", &R, &C)!=EOF) {
17         memset(dp, 0, sizeof(dp));
18         memset(cant, 0, sizeof(cant));
19         for(i = 1; i <= R; ++i) {
20             for(j = 1; j <= C; ++j) {
21                 scanf("%lf%lf%lf", &p[i][j][0], &p[i][j][1], &p[i][j][2]);
22                 if(fabs(p[i][j][0] - 1.0) > eps) {
23                     dp[i][j] = (dp[i][j - 1] + 2) * p[i][j - 1][1] + (dp[i - 1][j] + 2) * p[i - 1][j][2] + 2 * p[i][j][0];
24                     dp[i][j] /= (1 - p[i][j][0]);
25                     if(j==1)
26                         cant[i][j - 1] = 1;
27                     if(i==1)
28                         cant[i - 1][j] = 1;
29 
30                     if(cant[i][j - 1] && cant[i - 1][j] && (i != 1 || j != 1))
31                         cant[i][j] = 1, dp[i][j] = 0;
32                 }
33                 else
34                     cant[i][j] = 1, dp[i][j] = 0;
35                 //printf("%d %d dp[%d][%d] == %f\n",cant[i][j - 1], cant[i - 1][j], i, j, dp[i][j]);
36             }
37         }
38         dp[R][C] = 0;
39         if(!cant[R][C - 1])
40             dp[R][C] += (dp[R][C - 1] + 2) * p[R][C - 1][1];
41         if(!cant[R - 1][C])
42             dp[R][C] += (dp[R - 1][C] + 2) * p[R - 1][C][2];
43         printf("%.3f\n", dp[R][C]);
44     }
45 }

 

hdu 3853 写傻了的期望dp,不能正推?!!

标签:

原文地址:http://www.cnblogs.com/AC-Phoenix/p/4291000.html

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