Robberiestime limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/others) total submission (s): 11294 accepted submission (s): 4188
Problem descriptionthe aspiring Roy the robber has 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 has been assessing the security of varous 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, has decided upon a tolerable probability of getting caught. She feels that he is safe enough if the banks he robs together give a probability less than this.
Inputthe first line of input gives t, the number of instances. for each scenario, the first line of input gives a floating point number P, the probability Roy needs to be below, and an integer N, the number of banks he has plans. 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 is PJ.
Outputfor each test case, output a line with the maximum number of millions he can perform CT to get while the probability of getting caught is less than the limit set.
Notes and constraints
Zero <t <= 100
0.0 <= P <= 1.0
0 <n <= 100
0 <MJ <= 100
0.0 & lt; = PJ & lt; = 1.0
A bank goes bankrupt if it is robbed, and you may assume that all probabilities are independent as the police have 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
Roy wants to rob a bank. Each bank has a certain amount and a probability of being caught. He knows that Roy is arrested.
The maximum probability is P, which means Roy has the most robbery when caught.
Idea: 01 backpack problem. Use the probability of successful escape as "value" and the total amount of money in the bank as "backpack capacity ".
# Include <stdio. h> # include <iostream> using namespace STD; double DP [1000005]; double max (Double X, Double Y) {return (x> Y? X: Y) ;}int main () {int T, I, j; int m, a [105]; Double N, B [105]; int sum; cin> T; while (t --) {memset (DP, 0, sizeof (DP); CIN> N> m; sum = 0; for (I = 1; I <= m; I ++) {CIN> A [I]> B [I]; sum + = A [I]; // sum of the amount B [I] = 1-B [I]; // probability of successful escape} DP [0] = 1; // The probability of a successful escape is 1for (I = 1; I <= m; I ++) for (j = sum; j> = A [I]; j --) DP [J] = max (DP [J], DP [J-A [I] * B [I]); // perform multiplication for (I = sum; I> = 0; I --) {If (DP [I]> = 1-N) break ;} printf ("% d \ n", I);} return 0 ;}