Codeforces 167b wizards and huge prize probability dp (Water

Source: Internet
Author: User

Question link: Click the open link

Question:

Given n opponents, at least one of them will be defeated. Now there is a pocket CAPACITY OF K

The N numbers below indicate the probability of defeating this person.

The following n numbers (if-1 indicates that a gold coin can be obtained if this person is defeated, and if it is greater than 0, the pocket capacity can be increased to this number)

Q:

Beat at least one of them, and the total pocket capacity obtained> = the probability of the number of gold coins. (That is, gold coins cannot be stored at any time)


Ideas:

Probability DP

Note that it is possible that the pocket capacity is negative, but it turns into a positive number at the end, so we need to increase the pocket capacity by N,

# Include <iostream> # include <map> # include <string> # include <cstring> # include <cstdio> template <class T> inline bool RD (T & RET) {char C; int SGN; If (C = getchar (), c = EOF) return 0; while (C! = '-' & (C <'0' | C> '9') c = getchar (); SGN = (C = '-')? -1:1; ret = (C = '-')? 0 :( C-'0'); While (C = getchar (), c> = '0' & C <= '9 ') ret = RET * 10 + (c-'0'); RET * = SGN; return 1;} template <class T> inline void Pt (t x) {If (x <0) {putchar ('-'); X =-X;} If (x> 9) Pt (X/10 ); putchar (X % 10 + '0');} using namespace STD; const int n = 201; const double EPS = 1e-10; int n, l, D; double P [N], DP [N] [N] [N * 2 + 10]; // (I, j, k) indicates that the first one hits J, probability int B [N]; void input () {for (INT I = 1, J; I <= N; I ++) {RD (j); P [I] = (double) J/100.0;} For (INT I = 1; I <= N; I ++) rd (B [I]);} int main () {While (CIN> N> L> d) {input (); memset (DP, 0, sizeof DP); DP [0] [0] [d + N] = 1.0; For (INT I = 1; I <= N; I ++) for (Int J = 0; j <I; j ++) for (int K = 0; k <= 2 * n; k ++) {If (B [I] =-1) {If (k> 0) DP [I] [J + 1] [k-1] + = DP [I-1] [J] [k] * P [I];} else {If (K + B [I]> N * 2) DP [I] [J + 1] [N * 2] + = DP [I-1] [J] [k] * P [I]; elsedp [I] [J + 1] [K + B [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 = L; I <= N; I ++) for (Int J = N; j <= 2 * n; j ++) ans + = DP [N] [I] [J]; printf ("%. 10f \ n ", ANS);} return 0 ;}


Codeforces 167b wizards and huge prize probability dp (Water

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.