HDU 1203 I need A offer! (01 Backpack)

Source: Internet
Author: User
Tags first row

I need A offer!
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 18689 Accepted Submission (s): 7492


Problem Description speakless very early want to go abroad, now he has finished all the required examinations, prepared all the materials to prepare, so, then need to apply for school. To apply for any university abroad, you have to pay a certain amount of application fees, which is very alarming. Speakless didn't have much money, only a total of n million dollars. He will choose a number of M schools (certainly within his financial range). Each school has a different application fee of a (million dollars), and speakless estimates the likelihood of his getting a offer from this school B. Whether or not there is an offer between different schools will not affect each other. "I need a offer," he shouted. Help the poor man, help him calculate the maximum probability that he can receive at least one offer. (if Speakless chooses more than one school, get an offer from any school).

Input has several sets of data, and the first row of each group of data has two positive integers n,m (0<=n<=10000,0<=m<=10000)
In the following M-line, each row has two data ai (integer), and Bi (real) represents the application fee for the I-school and the probability of getting an offer.
The last entry has two 0.

Output each set of data corresponds to an export, indicating the maximum probability that speakless may get at least one offer. Expressed as a percentage, accurate to one decimal place.

Sample Input

10 3 4 0.1 4 0.2 5 0.3 0 0
Sample Output
44.0% Hint You should use printf ("percent") to print a '% '.
Author speakless
Source Gardon-dygg Contest 2
Recommend jgshining


Parsing: Using a simple probability transformation formula, P (ABCD ...) = 1-p (! A! B! C! D ...), to seek probabilities indirectly by opposing events.

Use 01 backpack to find out the probability of non-acceptance of the minimum p, and then 1-p is the request.




AC Code:

#include <bits/stdc++.h>
using namespace std;

const int MAXN = 10005;
int n, M, W[MAXN];
Double V[MAXN];

Double DP[MAXN + 1];      Two-dimensional arrays will be mle ...

void Zeroonepack () {for
    (int i=0; i<=n; i++) dp[i] = 1;
    for (int. i=0; i<m; i++)
        for (int j=n; j>=w[i]; j--)
            dp[j] = min (Dp[j], dp[j-w[i]] * v[i]);
}

int main () {
    #ifdef sxk
        freopen ("In.txt", "R", stdin);
    #endif//Sxk while
    (~scanf ("%d%d", &n, &m)) {
        if (!n &&!m) break;
        for (int i=0; i<m; i++) {
            scanf ("%d%lf", &w[i], &v[i]);
            V[i] = 1-v[i];
        }
        Zeroonepack ();
        printf ("%.1lf%%\n", (1-dp[n]) *);
    }
    return 0;
}


PS: Look at you big backpack code, mostly with one-dimensional array write, at that time also wonder, this is what new posture, the original is an array of reuse AH ~ ~ ~




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.