• Codeforces Round #114 (Div. 1) B. Wizards and Huge Prize 概率dp


    B. Wizards and Huge Prize

    Time Limit: 20 Sec

    Memory Limit: 256 MB

    题目连接

    http://codeforces.com/contest/167/problem/B

    Description

    One must train much to do well on wizardry contests. So, there are numerous wizardry schools and magic fees.

    One of such magic schools consists of n tours. A winner of each tour gets a huge prize. The school is organised quite far away, so one will have to take all the prizes home in one go. And the bags that you've brought with you have space for no more than k huge prizes.

    Besides the fact that you want to take all the prizes home, you also want to perform well. You will consider your performance good if you win at least l tours.

    In fact, years of organizing contests proved to the organizers that transporting huge prizes is an issue for the participants. Alas, no one has ever invented a spell that would shrink the prizes... So, here's the solution: for some tours the winner gets a bag instead of a huge prize. Each bag is characterized by number ai — the number of huge prizes that will fit into it.

    You already know the subject of all tours, so you can estimate the probability pi of winning the i-th tour. You cannot skip the tour under any circumstances.

    Find the probability that you will perform well on the contest and will be able to take all won prizes home (that is, that you will be able to fit all the huge prizes that you won into the bags that you either won or brought from home).

    Input

    The first line contains three integers nlk (1 ≤ n ≤ 200, 0 ≤ l, k ≤ 200) — the number of tours, the minimum number of tours to win, and the number of prizes that you can fit in the bags brought from home, correspondingly.

    The second line contains n space-separated integers, pi (0 ≤ pi ≤ 100) — the probability to win the i-th tour, in percents.

    The third line contains n space-separated integers, ai (1 ≤ ai ≤ 200) — the capacity of the bag that will be awarded to you for winning the i-th tour, or else -1, if the prize for the i-th tour is a huge prize and not a bag.

    Output

    Print a single real number — the answer to the problem. The answer will be accepted if the absolute or relative error does not exceed10 - 6.

     

    Sample Input

    3 1 0
    10 20 30
    -1 -1 2

    Sample Output

    0.300000000000

    HINT

    题意

    有n个人,你需要至少打败l个人,你一开始的背包容量是k

    打败每个人的概率是p[i],如果a[i]=-1,那么说明这个人打败之后,会给你奖品,否则就会给你一个容量为a[i]的背包

    每个奖品带回家,都需要容量为1的背包

    问你至少打败l个人,并且把胜利品全部都能带回去的概率是多少

    题解:

    dp[i][j][k]表示我目前挑战到第i个人,打败了j个人,我把所有胜利品都背回去之后的背包剩余容量为k

    然后转移转移就好了~

    代码:

    #include<iostream>
    #include<stdio.h>
    #include<math.h>
    using namespace std;
    
    int tmp = 300;
    double dp[215][215][615];
    double p[215];
    int a[215];
    int main()
    {
        int n,l,k;
        scanf("%d%d%d",&n,&l,&k);
        for(int i=1;i<=n;i++)
        {
            scanf("%lf",&p[i]);
            p[i]/=100.0;
        }
        for(int i=1;i<=n;i++)
            scanf("%d",&a[i]);
        dp[0][0][tmp+k]=1;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<=i;j++)
            {
                for(int t=0;t<=600;t++)
                {
                    if(a[i+1]==-1)
                    {
                        if(t>0)dp[i+1][j+1][t-1] += dp[i][j][t] * p[i+1];
                        dp[i+1][j][t] += dp[i][j][t]*(1-p[i+1]);
                    }
                    else
                    {
                        int pl = min(t + a[i+1],600);
                        dp[i+1][j+1][pl] += dp[i][j][t]*p[i+1];
                        dp[i+1][j][t] += dp[i][j][t]*(1-p[i+1]);
                    }
                }
            }
        }
        double ans = 0;
        for(int i=l;i<=n;i++)
            for(int j=tmp;j<=610;j++)
                ans += dp[n][i][j];
        printf("%.10f
    ",ans);
    }
  • 相关阅读:
    a
    QR Code Error Correction
    Beating JSON performance with Protobuf https://auth0.com/blog/beating-json-performance-with-protobuf/
    公共错误码
    风险识别系统-大数据智能风控管理平台-企业风控解决方案– 阿里云 https://www.aliyun.com/product/saf
    python3 源码阅读-虚拟机运行原理
    Crypto.getRandomValues()
    Profile Guided Optimization Link Time Optimization
    需要更多从文献资料中借鉴他人的方法与成果
    RSA2对于所有商户都是单独一对一的,并且只支持开发平台密钥管理和沙箱
  • 原文地址:https://www.cnblogs.com/qscqesze/p/4987957.html
Copyright © 2020-2023  润新知