标签:
//下面是错误代码...
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 }
标签:
原文地址:http://www.cnblogs.com/AC-Phoenix/p/4291000.html