Main topic:
First give a few sets of data, each set of data is the total catch probability p (the total probability of the final estimate can not be greater than him, or be caught), and then is to rob the number of banks N. Then n rows, each line is the bank can rob the amount of money m[i] and the probability of being caught p[i], in the case of not being caught can rob the amount of money;
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 31 0.022 0.033 0.050.06 32 0.032 0.033 0.050.10 31 0.032 0.023 0.05
Sample Output246 topic meaning: A thief want to steal the money of the bank, this small secretly every bank was caught probability of pi, thief as long as the probability of stealing every bank failure is less than P will not be caught, beg thief not to be caught in the case of the maximum amount of money can be invested? Analysis: Small secretly each bank failure probability is pi, then the probability of success is (1-PI); Given the failure probability range of the stolen bank is less than P security, then as long as the thief stole the bank the probability of success is greater than (1-P) is safe; The problem is the maximum amount of money stolen in the max not caught probability p, The maximum probability of conversion to a given amount of money stolen. Dp[j] indicates the maximum probability of successful stealing of the money in J case. Dp[j]=max (dp[j],dp[j-m[i]]* (1-PI)); Code:
1 ImportJava.util.Scanner;2 3 Public classTest1 {4 5 Public Static voidMain (string[] args) {6 7 Double[] dp=New Double[10005];8 int[] m=New int[105];9 Double[] p=New Double[105];Ten OneScanner input=NewScanner (system.in); A intt=input.nextint (); - intsum,n,i,j; - DoubleP; the - while(T--! =0) { - -Sum=0; +p=input.nextdouble (); -P=1-P; +n=input.nextint (); A at for(i=0;i<n;i++) { - -m[i]=input.nextint (); -p[i]=input.nextdouble (); -P[i]=1-P[i]; -sum+=M[i]; in - } to +Dp[0]=1; - for(i=0;i<n;i++) { the * for(j=sum;j>=m[i];j--) { $ Panax NotoginsengDp[j]=math.max (dp[j],dp[j-m[i]]*p[i]); - the } + } A the for(i=sum;i>=0&&dp[i]<p;i--); + - System.out.println (i); $ $ - } - } the}
The idea is this idea ah, why can't ac?
hdu2955 robberies (Java)