Codeforces 167B Wizards and Huge Prize (probabilistic DP)

Source: Internet
Author: User

Test instructions

n individuals, starting with a capacity of a K-pack, defeating a person's backpack can get a certain capacity or get a fortune (put in a backpack), give the probability of defeating each person, and ask at least to beat the L person, and the backpack capacity is greater than the probability of total wealth obtained

Analysis:

State OK, Dp[i][j][k] said before I personally beat J backpack capacity is k is the probability, the probability is pushing, to pay attention to the backpack capacity can be negative, we add capacity to B.

#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)#defineB 201Constll infll =0x3f3f3f3f3f3f3f3fll;Const intinf=0x7ffffff;Const intMoD =1000000007;Doubledp[ About][ About][2*b+Ten];inta[ About],p[ About];intn,l,k;voidsolve () {memset (DP,0,sizeof(DP)); dp[0][0][b+k]=1;  for(intI=1; i<=n;++i) for(intj=0; j<=i;++j) for(intk=0; k<=2*b;++k) {Dp[i][j][k]+=dp[i-1][j][k]* (1-p[i]/100.0)//did not beat the first I personif(a[i]==-1){                if(k>0)//must be able to put down a fortune dp[i][j+1][k-1]+=dp[i-1][j][k]* (p[i]/100.0); }            Else{            if(k+a[i]>2*B) Dp[i][j+1][2*b]+=dp[i-1][j][k]* (p[i]/100.0); Elsedp[i][j+1][k+a[i]]+=dp[i-1][j][k]* (p[i]/100.0); }        }
The probability of qualifying conditions and
DoubleTotal=0.0; for(intj=l;j<=n;++j) for(intk=b;k<=2*b;++k) Total+=Dp[n][j][k]; printf ("%.12lf\n", total);}intMain () { while(~SCANF ("%d%d%d",&n,&l,&k)) { for(intI=1; i<=n;++i) scanf ("%d",&P[i]); for(intI=1; i<=n;++i) scanf ("%d",&A[i]); Solve (); }return 0;}

Codeforces 167B Wizards and Huge Prize (probabilistic 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.