HDU 2955 robberies

Source: Internet
Author: User

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


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 Input
 
30.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 output
 246 meaning: if you want to calculate that the probability of a robbery being arrested does not exceed P, you can find the money he can grab the most! TIPS: will the robbers kidnap the world champion after reading this question? =   it's still a problem to change the model to a 0-1 backpack! You must think more about it before you can feel it!   AC code: 
 # include 
    
      # include 
     
       int MJ [105]; double PJ [105], DP [10005]; int main () {int N, I, j, sum, T; Double P; scanf ("% d", & T); While (t --) {scanf ("% lf % d", & P, & N); P = 1-P; sum = 0; memset (DP, 0, sizeof (DP); DP [0] = 1; for (I = 0; I 
      
        = MJ [I]; j --) {If (DP [J] 
       
         = 0 & DP [I] 
         
         

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.