HDU 1203 I NEED A offer! (01 backpack) __ Backpack

Source: Internet
Author: User

I NEED A offer!

Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 24607 accepted Submission (s): 9917

Problem Description
Speakless very early wanted to go abroad, now he has finished all the necessary exams, prepared all the materials to be prepared, so, they need to apply for school. To apply for any university abroad, you have to pay a certain application fee, which is very amazing. Speakless did not have much money, the total only saved n million dollars. He will choose a number of schools in M (certainly within the scope of his financial sustainability). Each school has a different application fee of a (million dollars), and Speakless estimated his chances of getting the offer from the school B. The availability of an offer between schools will not affect each other. "I NEED a offer", he yelled. 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
Enter a number of sets of data, with two positive integers in the first row of each set of data n,m (0<=n<=10000,0<=m<=10000)
After the M line, each row has two data ai (integer), bi (real) represents the first school of the application fee and may be the probability of getting an offer.
The last entry has two 0.

Output
Each set of data corresponds to one output, indicating that the speakless may receive at least one offer of the maximum probability. Expressed as a percentage, accurate to one of the decimal places.

Sample Input
10 3
4 0.1
4 0.2
5 0.3
0 0

Sample Output
44%

Hint

You are should use printf ("percent%") to print a '% '.

Typical 01 backpack, the code is as follows:

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm >
#include <math.h>
using namespace std;
#define MIN (a,b) (A<B?A:B)
#define MAX (a,b) (A<B?A:B)
int main ()
{
    int n,m,a[10011];
    Double f[10011],b[10011];
    while (scanf ("%d%d", &m,&n) && (n+m)!=0)
    {for
        (int i=0; i<n; i++)
        {
            scanf ("%d% LF ", &a[i],&b[i]);
            B[i]=1-b[i];
        }
        for (int i=0;i<=m;i++)
        {
            f[i]=1
        }
        for (int i=0; i<n; i++)
        {for
            (int j=m; j>=a[i]; j--)
            {
                F[j]=max (f[j],f[j-a[i]]*b[i));
        }
        printf ("%.1lf%%\n", (1-f[m]) *100);
    }
    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.