Maximum Random Walk (probability dp)

Source: Internet
Author: User

Test instructions

Walk n step, give each step to the left to go the probability of L, the right to go to the probability of R, left in situ probability 1-l-r, to achieve the farthest right distance expectation.

Analysis

Start in the way of the desire to reverse the analysis, but let is the right edge can not retreat, Meng a will, since the inverse cannot beg, first is to seek probability, and then according to the definition of expectations, try it, think of State, Dp[i][j][k], said I step the current position is J the farthest right boundary is k when the probability, Because the position can be negative, the position is added N.

#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#defineN 110#defineRead Freopen ("In.txt", "R", stdin)Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doubledp[n][2*N] [N],l,r;intMain () {intn,o,t; scanf ("%d",&t);  while(t--) {scanf ("%D%D%LF%LF",&o,&n,&l,&R); Memset (DP,0,sizeof(DP)); dp[0][n][n]=1;  for(intI=0; i<n;++i) {             for(intj=0; j<=2*n;++j) for(intk=j;k<=2*n;++k) {dp[i+1][j][k]+=dp[i][j][k]* (1-LR); Dp[i+1][j-1][k]+=dp[i][j][k]*M; if(j+1>k) Dp[i+1][j+1][k+1]+=dp[i][j][k]*R; ElseDp[i+1][j+1][k]+=dp[i][j][k]*R; }        }         //definition of expectations        DoubleTotal=0.0;  for(intj=0; j<=2*n;++j) for(intk=j;k<=2*n;++k) Total+=dp[n][j][k]* (K-N); printf ("%d%.4lf\n", O,total); }return 0;} 

Maximum Random Walk (probability dp)

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.