HDU 1203 I need a offer! (DP | backpack)

Source: Internet
Author: User
HDU 1203 I need a offer!

Http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1203

Problem descriptionspeakless wanted to go abroad very early. Now he has completed all the required tests and prepared all the materials, so he needs to apply for a school. To apply for a foreign university, you have to pay a certain amount of application fee, which is amazing. Speakless does not cost much, and only saves tens of thousands of dollars in total. He will select several of M schools (of course, within his economic limits ). Each school has a different application fee (USD), and speakless estimates that he is more likely to receive an offer from the school. Whether an offer is obtained from different schools does not affect each other. "I need a offer", he shouted. Help this poor person. Help him calculate the maximum probability that he can receive at least one letter of offer. (If you select multiple schools for speakless, you can get an offer from any school ).

Input has several groups of data. The first row of each group of data has two positive integers n, m (0 <=n <= random, 0 <= m <= 10000)
In the next m row, each row has two data types: AI (integer type) and Bi (real type), which respectively indicate the application fee of the I-th School and the probability of obtaining an offer.
The last two zeros are entered.

Each group of output data corresponds to one output, indicating that speakless may obtain at least one offer. Expressed as a percentage, accurate to the last decimal point.

Sample input10 3 4 0.1 4 0.2 5 0.3 0 0

Sample output44.0 %

 

 

The question requires at least one probability, including the probability of one copy + the probability of two copies + .. + The probability of M Portions can be used to obtain the minimum probability that an offline employee cannot be obtained. f [J] indicates the minimum probability that a zero portion is received when J s are used.
State transition equation: F [J] = min {f [J-A [I] * B [I]} (A [I] <= j <= N)
The probability of at least one copy is 1-min (F [J]).

 

# include
using namespace STD;
# define Max 10001
float DP [Max];
int main ()
{< br> int M, N;
while (~ Scanf ("% d", & M, & N), m + n)
{< br> int I, j, a [Max];
float B [Max];
for (I = 1; I <= N; I ++)
scanf ("% d % F ", & A [I], & B [I]);
for (j = 0; j <= m; j ++)
DP [J] = 1;
for (I = 1; I <= N; I ++)
for (j = m; j> = A [I]; j --)
If (DP [J]> DP [J-A [I] * (1-B [I])
DP [J] = DP [J-A [I] * (1-B [I]);
printf ("%. 1f % \ n ", (1-dp [m]) * 100);
}< br> 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.