hdu 3853 機率DP 簡單

來源:互聯網
上載者:User

標籤:style   http   color   os   io   for   amp   line   

http://acm.hdu.edu.cn/showproblem.php?pid=3853

題意:有R*C個格子,一個傢伙要從(0,0)走到(R-1,C-1) 每次只有三次方向,分別是不動,向下,向右,告訴你這三個方向的機率,以及每走一步需要耗費兩個能量,問你走到終點所需要耗費能量的數學期望:

回頭再推次,思想跟以前的做過的類似

注意點:分母為0的處理

#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <iostream>#include <iomanip>#include <cmath>#include <map>#include <set>#include <queue>using namespace std;#define ls(rt) rt*2#define rs(rt) rt*2+1#define ll long long#define ull unsigned long long#define rep(i,s,e) for(int i=s;i<e;i++)#define repe(i,s,e) for(int i=s;i<=e;i++)#define CL(a,b) memset(a,b,sizeof(a))#define IN(s) freopen(s,"r",stdin)#define OUT(s) freopen(s,"w",stdout)const ll ll_INF = ((ull)(-1))>>1;const double EPS=1e-8;const int MAXN = 1000+100;double dp[MAXN][MAXN],mat[MAXN][MAXN][3];int r,c;int main(){    while(~scanf("%d%d",&r,&c))    {        CL(dp,0);        for(int i=1;i<=r;i++)            for(int j=1;j<=c;j++)                for(int k=0;k<3;k++)                    scanf("%lf",&mat[i][j][k]);        for(int i=r;i>0;i--)            for(int j=c;j>0;j--)            {                if(i==r && j==c)dp[i][j]=0;                if(abs(mat[i][j][0]-1.0)<EPS)continue;                dp[i][j]=(dp[i+1][j]*mat[i][j][2]+dp[i][j+1]*mat[i][j][1]+2)/(1.0-mat[i][j][0]);            }        printf("%.3lf\n",dp[1][1]);    }    return 0;}


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.