Challenge AcWing 232. Keepers (expected DP) Punch

Topic : https://www.acwing.com/problem/content/description/234/

Meaning of the questions : There are n times the challenges, each challenge wins can get a map of the debris can get a value of -1 or bags used to hold the map the debris, the beginning of a package, there is a probability of winning each challenge, now let you seeking to win at least L round, finished packaging challenges probability can be back at the wheel after n pieces of map

Ideas : First, we can observe a value of -1 to map the debris, the backpack is positive, that is to say the final sum adds up to a non-negative, then we can also see a map only negative -1, that is all for the map only debris-200, as long as we have a package can be installed in all 200, so there will be no excess use, and this problem should be divided every challenge to win or lose, a lot of cases, it should be apparent that a DP 

We dp [i] [j] [k], i represents the first of several challenges, j represents the number of rounds won, k represents the current value of the remaining space

My original idea was to open a 400 to 200 as the origin, so the middle is negative it will not overflow, then last as long as the calculation of> = 200 can be, but I seem to write a setback,

I changed the value of the first sort of challenge, from large to small, because the challenges are in no particular order, so we can put the challenge can receive bags of playing, so that negative cross-border problem does not occur

Finally, we just calculate j> = l can be of value

 

#include<bits/stdc++.h>
#define maxn  405
#define mod 1000000007
using namespace std;
typedef long long ll;
struct sss
{
    double x;
    ll y;
}a[maxn];
ll n,l,k;
double dp[2][maxn][maxn];
int cmp(struct sss x,struct sss y){
    return x.y>y.y;
}
int main(){
    scanf("%lld%lld%lld",&n,&l,&k);
    for(int i=1;i<=n;i++)   scanf("%lf",&a[i].x);
    for(int i=1;i<=n;i++)    scanf("%lld",&a[i].y);
    sort(a+1,a+n+1,cmp);
    dp[0][0][min(n,k)]=1;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=n;j++){
            for(int w=0;w<maxn;w++){
                if(w+a[i].y>=0)
                    dp[1][j+1][min(n,w+a[i].y)]+=dp[0][j][w]*a[i].x/100.0;
                dp[1][j][w]+=dp[0][j][w]*(1-a[i].x/100.0);
            }
        }
        for(int j=0;j<=n;j++){
            for(int w=0;w<maxn;w++){
                dp[0][j][w]=dp[1][j][w];
                dp[1][j][w]=0;
            }
        }
    }
    double sum=0;
    for(int i=l;i<=n;i++){
        for(int j=0;j<=n;j++){
            sum+=dp[0][i][j];
        } 
    }
    printf("%.6lf",sum);
}

 

Guess you like

Origin www.cnblogs.com/Lis-/p/11297578.html