hdu 3853 LOOPS 概率DP

简单的概率DP入门题

代码如下:

 

 1 #include<iostream>

 2 #include<stdio.h>

 3 #include<algorithm>

 4 #include<iomanip>

 5 #include<cmath>

 6 #include<cstring>

 7 #include<vector>

 8 #define ll __int64

 9 #define pi acos(-1.0)

10 #define MAX 1003

11 using namespace std;

12 struct point

13 {

14     double c,b,r;

15 }p[MAX][MAX];

16 double dp[MAX][MAX];

17 int main(){

18     int n,m,i,j;

19     while(scanf("%d%d",&n,&m)!=EOF){

20         for(i=1;i<=n;i++)

21             for(j=1;j<=m;j++)

22                 scanf("%lf%lf%lf",&p[i][j].c,&p[i][j].r,&p[i][j].b);

23         dp[n][m]=0.0;

24         for(i=n;i>=1;i--)

25         for(j=m;j>=1;j--){

26             if(i==n&&j==m) continue;

27             if(fabs(1-p[i][j].c)<1e-5) continue;

28             dp[i][j]=(p[i][j].r*dp[i][j+1]+p[i][j].b*dp[i+1][j]+2)/(1-p[i][j].c);

29         }

30         printf("%.3lf\n",dp[1][1]);

31     }

32     return 0;

33 }
View Code

 

 

 

你可能感兴趣的:(loop)