HDU 2955 robberies (01 backpack)

Source: Internet
Author: User
Robberies Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 12516 accepted submission (s): 4641
Problem descriptionthe aspiring Roy the robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. he has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.


For a few months now, Roy has been assessing the security of varous banks and the amount of cash they hold. He wants to make a calculated risk, and grab as much money as possible.


His mother, OLA, has decided upon a tolerable probability of getting caught. she feels that he is safe enough if the banks he robs together give a probability less than this. inputthe first line of input gives t, the number of instances. for each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans. then follow n lines, where line J gives an integer MJ and a floating point number PJ.
Bank J contains MJ millions, and the probability of getting caught from robbing it is PJ. outputfor each test case, output a line with the maximum number of millions he can perform CT to get while the probability of getting caught is less than the limit set.

Notes and constraints
Zero <t <= 100
0.0 <= P <= 1.0
0 <n <= 100
0 <MJ <= 100
0.0 & lt; = PJ & lt; = 1.0
A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds. sample input30.04 31 0.022 0.033 0.050.06 32 0.032 0.033 0.050.10 31 0.032 0.023 0.05 sample output246

Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 12516 accepted submission (s): 4641


Problem descriptionthe aspiring Roy the robber has seen a lot of American movies, and knows that the bad guys usually gets caught in the end, often because they become too greedy. he has decided to work in the lucrative business of bank robbery only for a short while, before retiring to a comfortable job at a university.


For a few months now, Roy has been assessing the security of varous banks and the amount of cash they hold. He wants to make a calculated risk, and grab as much money as possible.


His mother, OLA, has decided upon a tolerable probability of getting caught. She feels that he is safe enough if the banks he robs together give a probability less than this.

 

Inputthe first line of input gives t, the number of instances. for each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans. then follow n lines, where line J gives an integer MJ and a floating point number PJ.
Bank J contains MJ millions, and the probability of getting caught from robbing it is PJ.

 

Outputfor each test case, output a line with the maximum number of millions he can perform CT to get while the probability of getting caught is less than the limit set.

Notes and constraints
Zero <t <= 100
0.0 <= P <= 1.0
0 <n <= 100
0 <MJ <= 100
0.0 & lt; = PJ & lt; = 1.0
A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have very low funds.

 

Sample input30.04 31 0.022 0.033 0.050.06 32 0.032 0.033 0.050.10 31 0.032 0.023 0.05

 

Sample output2 4 6 general meaning: the hero wants to obtain the greatest benefit from the bank, but this is risky, that is, to avoid being caught. Enter a number T, which indicates that there are several groups of test data. Then, enter two numbers N and m, respectively, indicating the total probability of being caught and several banks. The following describes the benefits that can be obtained from M's bank and the probability of being caught. Find the maximum number of benefits that the hero can obtain at least N. Train of Thought: here we should first consider the accuracy issue. The most important thing is to look for the dynamic transfer equation. we can regard the money in the used bank as the backpack capacity, the money in each bank as the weight, and the probability of being caught as the value. The transfer equation is: DP [J] = max (DP [J], DP [J-bag [I]. v] * (1-bag [I]. p ));
# Include <iostream> # include <algorithm>Using namespaceSTD;IntDP[500010];StructNode{IntMoney;DoubleP;}Bank[5555];IntMain(){IntT,N,I,J,Sum;DoubleP;Scanf("% D",&T);While(T--)// Test Data{Sum=0;Scanf("% Lf % d",&P,&N);// Probability of being caught and several banks P=1-P;For(I=0;I<N;I++ ){Scanf("% D % lf",&Bank[I].Money,&Bank[I].P);// Value and probability bank[I].P=1-Bank[I].P;Sum+ =Bank[I].Money;}DoubleDP[10005] = {1.0};// Memset (DP, 0, sizeof (DP ));For(I=0;I<N;I++ ){For(J=Sum;J> =Bank[I].Money;J--){If(DP[J-Bank[I].Money] *Bank[I].P>DP[J])DP[J] =DP[J-Bank[I].Money] *Bank[I].P;}}For(I=Sum;I> =0;I--){If(DP[I]-P>0.000000001){Printf("% D \ n",I);Break;}}}Return0;}

HDU 2955 robberies (01 backpack)

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.