hdu2955 robberies (01 backpack)

Source: Internet
Author: User

I'm the only one who thinks this test instructions difficult to understand ...


First give a few sets of data, each set of data is the total catch probability p (the total probability of the final estimate must be less than he, or be caught), and then is to rob the number of banks N. Then n rows, each row is the bank can rob the amount of money m[i] and the probability of being caught p[i], to find the maximum probability of escape. The greater the probability of being caught, the smaller the probability of escape.


The 1th is the most likely to make a mistake, the total probability of being caught as a backpack capacity. There are two obvious mistakes, that is, 1-the probability of being caught = the probability of escape, the restriction condition and the maximum knapsack capacity cannot be the same attribute. Moreover, the probability is more floating point number, the accuracy is not high can not traverse. So the backpack capacity must be money, because he can rob the bank is limited, the amount of money is also limited. Then is the maximum probability of escape, and each of the questions given is the probability of being caught, so we have to first be 1 minus a bit. And finally, the probability of escape with the number of banks to reduce, more rob a bank, its money will be converted into the product of probability, so the dynamic equation also to make changes. The last traversal, the more money remaining, indicating that the less money to rob, the greater the probability of escape. So from large to small traversal backpack capacity, once greater than p, that is, the maximum probability of jumping out.


This should be written to compare the experience of the field, the main problem is more to think about or quite interesting ~

#include <stdio.h> #include <algorithm> #include <iostream> #include <cmath> #include <

String.h> using namespace std;

const int N = 50005;
    int main () {//Freopen ("In.txt", "R", stdin);
    int T, M0, m[n];
    Double P0, P[n], ans[n];
    scanf ("%d", &t);
        while (T--) {scanf ("%lf%d", &p0, &AMP;M0);
        int sum = 0;
            for (int i = 0; i < M0; i + +) {scanf ("%d%lf", &m[i], &p[i]);
        Sum + = M[i];
        } memset (ans, 0, sizeof (ans));
        Ans[0] = 1; for (int i = 0; i < M0; i + +) {for (int j = sum; J >= M[i]; J--) {A
            NS[J] = max (Ans[j], Ans[j-m[i]] * (1-p[i]));
                }} for (int i = sum; I >= 0; I-) {if (Ans[i] > (1-p0)) {
                printf ("%d\n", I);
            Break
}}} return 0; }


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.