标签:
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 3163 Accepted Submission(s): 1279
比较简单的概率dp
简单求期望,常规逆推
d[i][j]表示距出口的期望能量消耗
d[i][j] = p1 * d[i + 1][j] + p2 * d[i][j + 1] + p3 * d[i][j] + 2;
#include <cstdio> #include <iostream> #include <sstream> #include <cmath> #include <cstring> #include <cstdlib> #include <string> #include <vector> #include <map> #include <set> #include <queue> #include <stack> #include <algorithm> using namespace std; #define ll long long #define _cle(m, a) memset(m, a, sizeof(m)) #define repu(i, a, b) for(int i = a; i < b; i++) #define repd(i, a, b) for(int i = b; i >= a; i--) #define MAXN 1005 struct P{ double o, d, r; }ma[MAXN][MAXN]; double d[MAXN][MAXN]; int main() { int r, c; while(~scanf("%d%d", &r, &c)) { repu(i, 1, r + 1) repu(j, 1, c + 1) scanf("%lf%lf%lf", &ma[i][j].o, &ma[i][j].r, &ma[i][j].d); repd(i, 1, r) repd(j, 1, c) { if(i == r && j == c) d[r][c] = 0.0; else { if(ma[i][j].o != 1.0) d[i][j] = (d[i + 1][j] * ma[i][j].d + d[i][j + 1] * ma[i][j].r + 2.0) / (1.0 - ma[i][j].o); else d[i][j] += 2.0; } } printf("%.3lf\n", d[1][1]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/sunus/p/4446023.html