Robberies
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 15522 Accepted Submission (s): 5708
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 Input3 0.04 31 0.022 0.033 0.050.06 32 0.03 2 0.03 3 0.05 0.10 3 1 0.03 2 0.02 3 0.05 01 backpack The amount of money as a backpack, the probability of not being caught as the items to be put attention : Assuming that the two banks are not caught the probability of two are not caught probability of product
#include <stdio.h> #include <string.h> #define MAX 10001#define max (x, y) (x>y?x:y) int price[110];d ouble Wei[110],dp[max];int Main () { int n,j,i,t,money; Double p,w; scanf ("%d", &t); while (t--) { scanf ("%lf%d", &w,&n); money=0; for (i=0;i<n;i++) { scanf ("%d%lf", &price[i],&wei[i]); Money+=price[i]; Wei[i]=1-wei[i]; } Memset (Dp,0,sizeof (DP)); Dp[0]=1; for (i=0;i<n;i++) {for (j=money;j>=price[i];j--) { Dp[j]=max (Dp[j],dp[j-price[i]]*wei [i]); } } p=1-w; for (i=money;i>=0;i--) { if (dp[i]>=p) { printf ("%d\n", I); Break ; }}} return 0;}
Sample Output2 4 6
Hdoj 2955 Robberies