double b[maxn]; double p[maxn][15]; int main() { // freopen("in.txt", "r", stdin); while (~RII(n, m) && n) { FE(i, 1, n) FE(j, 1, m) RI(c[i][j]); FF(i, 1, n) { double sum = 1, s = 0; FE(j, 1, m) sum += c[i][j]; FE(j, 1, m) { if (i - j >= 1) s += p[i][m - j] = 0.3 * c[i][j] / sum; if (i + j <= n) s += p[i][m + j] = 0.7 * c[i][j] / sum; } p[i][m] = -s; b[i] = -1; } FED(i, n - 1, 1) { int l = max(1, i - m), r = min(n - 1, i + m); FF(j, l, i) { double f = p[j][m - j + i] / p[i][m]; FE(k, l, r) p[j][m - j + k] -= p[i][m - i + k] * f; b[j] -= f * b[i]; } } printf("%.2f\n", b[1] / p[1][m]); } return 0; }
2013ACM-ICPC杭州赛区全国邀请赛——Random Walk,布布扣,bubuko.com
2013ACM-ICPC杭州赛区全国邀请赛——Random Walk
原文:http://blog.csdn.net/wty__/article/details/25415585