• [codeforces167B]Wizards and Huge Prize


    B. Wizards and Huge Prize
    time limit per test:
    2 seconds
    memory limit per test:
    256 megabytes
    input:
    standard input
    output:standard output

    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.

    Examples
    input
    3 1 0
    10 20 30
    -1 -1 2
    output
    0.300000000000
    input
    1 1 1
    100
    123
    output
    1.000000000000
    Note

    In the first sample we need either win no tour or win the third one. If we win nothing we wouldn't perform well. So, we must to win the third tour. Other conditions will be satisfied in this case. Probability of wining the third tour is 0.3.

    In the second sample we win the only tour with probability 1.0, and go back home with bag for it.

    题解

    这大概是我第一道不是图上的概率

    刚开始的时候都没有什么思路......果然dp还是要多刷题

    我们设f[i][j][k]为"前i天赢了j场,剩余空间为k"的概率

    通过十分艰苦地读题,不难发现,k在超过200后就没有什么用了,所以k只需要枚举0~200

    但我们还发现这些比赛是无序的,也就是说我们可以先去拿后面的包,再去拿前面的奖,所以我们必须把它变成无序的.

    考虑把k都加上200(诡异的思路......),这样前面的奖品也可以先选上(+200后是正的),再去后面选包,这样就可以随意处理了

    这样最后在200<=k<=400,l<=j<=n的范围内枚举所有f[n][j][k]即可(现在的200意味着原来的0,小于200意味着剩余空间为负值)

    代码见下:

    #include<cstdio>
    #include<cstring>
    #include<cmath>
    #include<algorithm>
    using namespace std;
    const int N=210;
    double p[N],k[N];
    int n,l,s,b[N];
    double f[N][N][2*N];
    int main()
    {
        scanf("%d%d%d",&n,&l,&s);
        for(int i=1;i<=n;i++)
            scanf("%lf",&p[i]),p[i]/=100,k[i]=1.0-p[i];
        for(int i=1;i<=n;i++)
            {scanf("%d",&b[i]);}
        f[0][0][s+200]=1;
        for(int i=0;i<n;i++)
            for(int j=0;j<=i;j++)
                for(int v=0;v<=400;v++)
                {
                    int t=min(v+b[i+1],400);
                    f[i+1][j][v]+=f[i][j][v]*k[i+1];
                    if(t>=0)
                        f[i+1][j+1][t]+=f[i][j][v]*p[i+1];
                }
        double ans=0.0;
        for(int v=200;v<=400;v++)
            for(int j=l;j<=n;j++)
                ans+=f[n][j][v];
        printf("%.12lf",ans);    
    }
    codeforces167B
    Progress is not created by contented people.
  • 相关阅读:
    关于面向对象
    关于内存的划分和传引用传参数的区别
    关于目前我们专业的各种发展方向
    关于C语言底层
    关于游戏行业目前的形势
    关于jsp,javascript,php等语言
    鼠标滑动图片变大
    在Linux环境下mysql的root密码忘记解决方法
    百度网盘
    bootsrtap 主题元素
  • 原文地址:https://www.cnblogs.com/LadyLex/p/7001718.html
Copyright © 2020-2023  润新知