首页 > 代码库 > HDU 3853 LOOPS 概率dp(水
HDU 3853 LOOPS 概率dp(水
水水过~
#include <stdio.h> #include <cstring> #include <iostream> #include <map> #include <cmath> template <class T> inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c<'0'||c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0'&&c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template <class T> inline void pt(T x) { if (x <0) { putchar('-'); x = -x; } if(x>9) pt(x/10); putchar(x%10+'0'); } using namespace std; typedef unsigned long long ull; const double eps = 1e-10; const int N = 1005; int n, m; double mp[N][N][3], dp[N][N]; double solve(){ dp[n][m] = 0; for(int i = n; i ; i--) for(int j = m; j; j--) { if(i == n && j == m)continue; if(fabs(mp[i][j][0] - 1.0) < eps) { dp[i][j] = 0; } else { dp[i][j] = mp[i][j][1] * dp[i][j+1] + mp[i][j][2] * dp[i+1][j]; dp[i][j] += 2.0; dp[i][j] /= (1 - mp[i][j][0]); } } return dp[1][1]; } void input(){ for(int i = 1; i <= n; i++) for(int j = 1; j <= m; j++) scanf("%lf %lf %lf", &mp[i][j][0], &mp[i][j][1], &mp[i][j][2]); } int main(){ while(cin>>n>>m){ input(); printf("%.3f\n", solve()); } return 0; }
HDU 3853 LOOPS 概率dp(水
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。