<Span style = "color: # 3333ff;">/* handle Author: grant yuan time: 2014.7.19 aldorithm: 01 backpack + card precision 127e-01 backpack Basic time limit: 1000 ms memory limit: 32768kb 64bit Io format: % i64d & % i64usubmit statusdescriptionthe aspiring Roy the robber has seen a of Lot 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 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 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 */# include <iostream> # include <cstdio> # include <cstring> # include <cstdlib> # include <algorithm> using namespace STD; int P [105]; double F [105]; int N, T; double ff; double DP [100005]; // obtain the maximum probability int sum for money with the value of I to escape; int main () {CIN> T; while (t --) {sum = 0; scanf ("% lf % d", & ff, & N); For (INT I = 0; I <n; I ++) {scanf ("% d % lf", & P [I], & F [I]); sum + = P [I];} memset (DP, 0, sizeof (DP); DP [0] = 1; for (INT I = 0; I <n; I ++) for (Int J = sum; j> = P [I]; j --) {DP [J] = max (DP [J], DP [J-P [I] * (1-F [I]);} int m = 0; For (INT I = sum; I> = 0; I --) {If (DP [I] >=1-ff) {M = I; break ;}} cout <m <Endl ;}</span>
01 backpack + card precision HDU 2955