Codeforces 167B Wizards and Huge Prize probability DP

Source: Internet
Author: User

Test instructions: Given n opponents, at least to defeat the L-person, now has a pocket capacity of K below n numbers indicate the probability of defeating this person

The following n digits (if 1 means that a gold coin can be obtained by defeating the person, if the >0 means that the pocket capacity can be increased to this number)

>=: At least the number of gold coins obtained by defeating the L-individual and obtaining the total pocket capacity. (That is, no gold can be placed at any time)


Idea: Set Dp[i][j][k] indicates that the current former I person has defeated J person, and the remaining pocket capacity of k probability, simply push down the formula can be. One thing that needs to be major, maybe at the beginning

The remaining pocket capacity <0 later than 0, so add a constant does not let it be negative, as long as the last remaining capacity >=0 can be. See the code:

/********************************************************* file name:codeforces167B.cpp Author:kereo Create Time:2 015 Year February 01 Sunday 21:34 15 seconds *********************************************************/#include <iostream># include<cstdio> #include <cstring> #include <queue> #include <set> #include <map># include<vector> #include <stack> #include <cmath> #include <string> #include <algorithm> Using namespace Std;typedef long long ll;const int sigma_size=26;const int n=200+50;const int Maxn=100000+50;const int inf =0x3fffffff;const double eps=1e-8;const int mod=100000000+7, #define L (x) (x<<1) #define R (x) (x<<1|1) # Define PII Pair<int, int> #define MK (x, y) Make_pair ((×), (y)) int n,m,k;int a[n];d ouble p[n],dp[n][n][2*n+10];int        Main () {while (~scanf ("%d%d%d", &n,&m,&k)) {memset (dp,0,sizeof (DP));        dp[0][0][n+k]=1.0;            for (int i=1;i<=n;i++) {scanf ("%lf", &p[i]); p[i]/=100;       } for (int i=1;i<=n;i++) scanf ("%d", &a[i]);                    for (int i=1;i<=n;i++) {for (int. j=0;j<i;j++) {for (int k=0;k<=2*n;k++) {                    if (a[i] = =-1) {if (k) dp[i][j+1][k-1]+=dp[i-1][j][k]*p[i];                    } else Dp[i][j+1][min (2*n,k+a[i])]+=dp[i-1][j][k]*p[i];                dp[i][j][k]+=dp[i-1][j][k]* (1-p[i]);        }}} double ans=0;        for (int. i=m;i<=n;i++) for (int j=n;j<=2*n;j++) ANS+=DP[N][I][J];    printf ("%f\n", ans); }return 0;}


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