HDU-1203 I need A offer!

Source: Internet
Author: User

Problem descriptionspeakless very early want to go abroad, now he has finished all the required examinations, prepared all the materials to prepare, so, they 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 Input10 34 0.14 0.25 0.30 0

Sample output44.0% HintYou should use printf ("percent") to print a '% '. Train of thought: Do not know this is not a probability DP, positive solution is to apply 0-1 backpack template, on that basis slightly make some changes on the OK, this is not the focus I want to say is through this topic and upgrade my knowledge of 0-1 backpack, to DP understanding, Seems to be closer to the nature of knowledge. Below I try to sort out my thoughts: first of all, we're asking for the maximum probability that a former m school will admit at least one, that is, the smallest probability that a former m school does not record. Then we must consider which of these schools choose not to choose which can get optimal resolution. So for the first school, we face two choices, choose it and do not choose it ———— actually this is a very minor step, before I think about the knapsack problem often easy to get stuck is because this is confusing, if I choose and not to choose the first school is not the focus of our thinking, then where is the key? The key is that for the current school of the first, All you have to do is put his value to the Max ., that is, for all of the cost options that he can update, Check it one by one to see if it can get a lower "minimum probability that all schools will not accept", (here is a different place with 0-1 backpacks, using multiplication instead of simple addition) so in the future when we think about the type of the 0-1 backpack, the mind is not the final answer, but at every stage he can do the expansion ———— when we have all the expansion is done, In the end, we can just extract the results we need.
#include <iostream>#include<cstring>#include<cstdio>#defineMAX 10007#defineMin (a) (a) < (b)? (a):(B)using namespacestd;structjob{intCost ; Doubleprobability;};intMain () {intn,m;    Job J[max]; DoubleDp[max];  while(Cin>>n>>m && m+N) { for(inti =0; I <= n;i++) Dp[i]=1;  for(inti =1; I <= m;i++) Cin>>j[i].cost>>j[i].probability;  for(inti =1; I <= m;i++)              for(intK = n;k >= j[i].cost;k--) Dp[k]= Min (dp[k],dp[k-j[i].cost]* (1-j[i].probability)); printf ("%.1lf%%\n",(1-dp[n]) * -); }    return 0;}

HDU-1203 I need A offer!

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.