HDU 2955 Robberies

Source: Internet
Author: User

Robberies



Problem DescriptionThe Aspiring Roy the robber have seen a lot of American movies, and knows so 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 had been assessing the security of various 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, had decided upon a tolerable probability of getting caught. She feels that he's safe enough if the banks he robs together give a probability less than this.

Inputthe first line of input gives T, the number of cases. For each scenario, the first line of input gives a floating point number P, the probability Roy needs to is below, and an Integer N, the number of banks he has plans for. 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's Pj.

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

Notes and Constraints
0 < T <= 100
0.0 <= P <= 1.0
0 < N <= 100
0 < Mj <= 100
0.0 <= Pj <= 1.0
A Bank goes bankrupt if it is robbed, and your may assume that all probabilities be independent as the police have very lo W funds.

Sample Input30.04 0.022 0.033 0.050.06 + 0.032 0.033 0.050.10 to 0.032 0.023 0.05 sample Output246
1#include <cstdio>2#include <cstring>3#include <algorithm>4 using namespacestd;5 6 Const intmaxn=10005;7 8 intMain ()9 {Ten     DoubleP; One     DoubleP[MAXN],DP[MAXN]; A     intt,total,n,i,j; -     intV[MAXN]; -scanf"%d",&t); the      while(t--) -     { -Memset (DP,0,sizeof(DP)); -scanf"%lf%d",&p,&n); +          for(total=0, i=0; i<n;i++) -         { +scanf"%D%LF",&v[i],&p[i]); Atotal+=V[i]; at         } -dp[0]=1; -          for(i=0; i<n;i++) -              for(j=total;j>=v[i];j--) -             { -Dp[j]=max (dp[j],dp[j-v[i]]* (1-p[i])); in             } -          for(i=total;i>=0; i--) to             if(dp[i]>=1-P) +             { -printf"%d\n", i); the                  Break; *             } $     }Panax Notoginseng     return 0; -}

HDU 2955 Robberies

Related Article

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.