现在的位置: 首页 > 综合 > 正文

Codeforces 167 B. Wizards and Huge Prize

2017年11月24日 ⁄ 综合 ⁄ 共 2963字 ⁄ 字号 评论关闭

三维DP:dp[ i ][ j ][ k ]前i场赢j场剩余空间k的概率

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 thei-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 exceed 10 - 6.

Sample test(s)
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.

/**
 * Created by ckboss on 14-9-11.
 */

import java.util.*;

public class WizardsandHugePrize {

    static final int ZERO = 202, END = 404;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int N = in.nextInt(), L = in.nextInt(), K = in.nextInt();

        int[] rest = new int[N + 2];
        double[] p = new double[N + 2];
        double[][][] dp = new double[N + 2][N + 2][END + 2];

        for (int i = 1; i <= N; i++) {
            p[i] = in.nextDouble();
            p[i] /= 100.;
        }

        for (int i = 1; i <= N; i++) {
            rest[i] = in.nextInt();
        }

        dp[0][0][ZERO + K] = 1.0;

        for (int i = 1; i <= N; i++) {
            for (int j = 0; j < i; j++) {
                for (int k = 0; k <= END; k++) {

                    if (rest[i] != -1) {
                        int x = Math.min(k + rest[i], END);
                        dp[i][j + 1][x] += dp[i - 1][j][k] * p[i];
                    } else if (k > 0) {
                        dp[i][j + 1][k - 1] += dp[i - 1][j][k] * p[i];
                    }

                    dp[i][j][k] += dp[i - 1][j][k] * (1 - p[i]);
                }
            }
        }

        double ans = 0.0;
        for (int i = L; i <= N; i++) {
            for (int j = ZERO; j <= END; j++) {
                ans += dp[N][i][j];
            }
        }

        System.out.println(ans);
    }
}

抱歉!评论已关闭.