hdu 3853 LOOPS (機率dp),hdu3853

來源:互聯網
上載者:User

hdu 3853 LOOPS (機率dp),hdu3853

/*dp[i][j]表示(i,j)到(R,C)需要消耗的能量則:dp[i][j]=p1[i][j]*dp[i][j]+p2[i][j]*dp[i][j+1]+p3[i][j]*dp[i+1][j]+2;///+2 轉移到下一個能量要消耗2化簡得:dp[i][j]=((p2[i][j]*dp[i][j+1])+(p3[i][j]*dp[i+1][j])+2)/(1-p1[i][j]);*/# include <stdio.h># include <algorithm># include <string.h># include <iostream>using namespace std;double dp[1010][1010],p1[1010][1010],p2[1010][1010],p3[1010][1010];int main(){    int r,c,i,j;    while(~scanf("%d%d",&r,&c))    {        for(i=1;i<=r;i++)        {            for(j=1;j<=c;j++)                scanf("%lf %lf %lf",&p1[i][j],&p2[i][j],&p3[i][j]);        }        dp[r][c]=0;        for(i=r;i>=1;i--)        {            for(j=c;j>=1;j--)            {                if(i==r&&j==c)                    continue;                if(p1[i][j]==1)                    continue;                dp[i][j]=((p2[i][j]*dp[i][j+1])+(p3[i][j]*dp[i+1][j])+2)/(1-p1[i][j]);            }        }        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.