Description
The aspiring Roy the robber have 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 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.
Input
The 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.
Output
For each test case, output a line with the maximum number of millions he can expect to get while the probability of gettin G caught is less than the limit set.
Notes and Constraints 0 < T <= 0.0 <= P <= 1.0 0 < N <= 0 < Mj <= 100< c5> 0.0 <= Pj <= 1.0 A Bank goes bankrupt if it is robbed, and we may assume that all probabilities is INDEP Endent as the police has 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
1#include <cstdio>2#include <cstring>3 using namespacestd;4 intMain ()5 {6 intw[ -],n,t,i,j,sum;7 Doublep[ -],dp[13000],m;8scanf"%d",&t);9 while(t--)Ten { Onesum=0; AMemset (DP,0,sizeof(DP)); -scanf"%lf%d",&m,&n); -m=1-m; the for(i=1; i<=n;i++) - { -scanf"%d%lf",&w[i],&p[i]); -sum+=W[i]; +p[i]=1-P[i]; - } +dp[0]=1; A for(i=1; i<=n;i++) at { - for(j=sum;j>=w[i];j--) - if(dp[j]<dp[j-w[i]]*P[i]) -dp[j]=dp[j-w[i]]*P[i]; - } - for(i=sum;i>=0; i--) in { - if(dp[i]>m) to { +printf"%d\n", i); - Break; the } * } $ }Panax Notoginseng}
HDU 2955 robberies (backpack)