HDU 2955
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 <= 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 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 Test Instructions: Enter the T-group data, and then enter P,n p to indicate the maximum limit to be caught, N is the number of banks and then enter the amount of n bank and the probability of being caught, the probability of being caught is less than or equal to P, rob the maximum money. Train of thought: 01 backpack, the second cycle with the amount of money to rob, the value of the inside is to rob the underlying corresponding to the probability of being caught. The code is as follows;
#include <iostream>#include<algorithm>#include<cstdio>#include<cstring>using namespacestd;Doubledp[10005];intMain () {intt,n,sum,money[ the]; Doublep,p[ the]; scanf ("%d",&T); while(t--) {sum=0; scanf ("%lf%d",&p,&N); P=1-Q; for(intI=0; i<n; i++) { intD; DoubleF; scanf ("%D%LF",&d,&f); Money[i]=D; P[i]=1-F; Sum+=D; } memset (DP,0,sizeof(DP)); dp[0]=1; for(intI=0; i<n; i++) for(intJ=sum; j>=money[i]; j--) {Dp[j]=max (dp[j],dp[j-money[i]]*P[i]); } for(inti=sum;i>=0; i--) if(dp[i]>=P) {printf ("%d\n", i); Break; } } return 0;}
DP Getting Started---robberies