hdu1203 (01 simple backpack)

I NEED A OFFER!

 

Problem Description

Speakless long time I wanted to go abroad, and now he has finished all the required exams, prepare all the materials to be prepared, so they need to apply for school. To apply for any university abroad, you have to pay a fee to apply, this is very striking. Speakless not have much money, just to save a total of $ n million. He will select a number of (of course within his affordability range) in the m schools. Each school has a different application fee a (million dollars), and Speakless estimated he got the school offer the possibility of b. Whether the offer will not affect each other between different schools. "I NEED A OFFER", he cried. Help the poor folks, help him calculate that he could receive the maximum probability of at least one offer. (If you selected multiple Speakless school, get a school of any offer can be).

 

 

Input

There are several groups of data input, data of the first line of each of two positive integers n-, m (0 <= n-<= 10000,0 <= m <= 10000)
m behind the line, each line has two data ai (integer), bi (real) denote the i-th school application fee and may get the offer of probability.
Finally, there are two 0 inputs.

 

 

Output

Each set of data corresponds to an output representing Speakless possible to obtain the maximum probability of at least one offer. Expressed as a percentage, to the nearest 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("%%") to print a '%

 

P (at least a school admission) = 1-P (not an admission)

Therefore, equation of state maxsum [j] = max (maxsum [j], 1- (1-maxsum [j-mon [i]]) * (1-pro [i])); pro [j] i-school probability offer could get.

#include<iostream>
#include<string.h>
#include<algorithm>
#include <cstdio>
using namespace std;
int mon[10001];
float pro[10001];
float maxsum[10001];
int main(void)
{
    int n,m;
    while(cin>>n>>m&&(n||m))
    {
        memset(maxsum,0,sizeof(maxsum));
        for(int i=1;i<=m;i++)
        {
           cin>>mon[i]>>pro[i];
        }
        for(int i=1;i<=m;i++)
         for(int j=n;j>=mon[i];j--)
             maxsum[j]=max(maxsum[j],1-(1-maxsum[j-mon[i]])*(1-pro[i]));
         printf("%.1lf%%\n",maxsum[n]*100);
    }
    return 0;
}

 

发布了20 篇原创文章 · 获赞 3 · 访问量 5474

Guess you like

Origin blog.csdn.net/treble_csnd/article/details/81910071