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;
}