HDU 3853-loop (Probabilistic DP Primer)

Source: Internet
Author: User

Test instructions

R*c a square, starting from (a) in each square can be released magic (energy consumption 2) to know, after the release of Magic may be in situ, may reach the adjacent lattice or the right lattice, give the probability of the three

To reach the (r,c) lattice, consume the desired energy.

Analysis:

State OK, dp[i][j] means (i,j) to reach (R,C) also need energy value, then dp[r][c]=0,dp[1][1] is the answer

dp[i][j]=dp[i][j]*p[i][j][0]+dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2.0, re-move the item can be;

#include <map>#include<Set>#include<list>#include<cmath>#include<queue>#include<stack>#include<cstdio>#include<vector>#include<string>#include<cctype>#include<complex>#include<cassert>#include<utility>#include<cstring>#include<cstdlib>#include<iostream>#include<algorithm>using namespaceStd;typedef pair<int,int>Pii;typedefLong Longll;#defineLson l,m,rt<<1#definePi ACOs (-1.0)#defineRson m+1,r,rt<<11#defineAll 1,n,1#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doubledp[1010][1010],p[1010][1010][4];intr,c;voidsolve () {memset (DP,0,sizeof(DP));  for(inti=r;i>=1;--i) for(intj=c;j>=1;--j) {if(I==R&AMP;&AMP;J==C)Continue; if(p[i][j][0]==1.000)Continue;//means there's no way to go, just stay where you aredp[i][j]=dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2.0; DP[I][J]/=(1.0-p[i][j][0]); } printf ("%.3lf\n", dp[1][1]);}intMain () { while(~SCANF ("%d%d",&r,&c)) {         for(intI=1; i<=r;++i) for(intj=1; j<=c;++j) for(intk=0;k<3;++k) scanf ("%LF",&P[i][j][k]);    Solve (); }return 0;}

HDU 3853-loop (Probabilistic DP Primer)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.