Link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2955
Question:
The thief wants to steal money from the bank.
Give you the maximum probability of being caught, and n Banks
The N rows below represent the amount of money the bank has and the maximum probability of being arrested.
At this time, the key thing is how to write dynamic equations.
The 10 backpacks we learned are made up of two types: one is the maximum size of the backpack, and the other is the value and size of the items loaded into the backpack.
To simulate this process, first:
Use all bank money as the maximum volume of a backpack
The money of each bank is used as the volume of items.
So the probability of being captured is the value of an item.
Then we can easily introduce the dynamic equation we need:
DP [I] = max (DP [I], (DP [I-money] * (1-rp); // money: current bank money, RP: Current probability of being caught
The rest is the set template.
The AC code is as follows:
# Include <iostream> # include <stdio. h> using namespace STD; double DP [10050]; double RP; int num; double RP [10050]; int money [10050]; int sum; double max (double, double B) {If (A> B) return a; elsereturn B;} void zeroonepack (INT money, double RP) {int I; for (I = sum; i> = money; I --) DP [I] = max (DP [I], (DP [I-money] * (1-rp); // equation, storage probability (equivalent to value)} int main () {int case; scanf ("% d", & case); While (case --) {scanf ("% lf % d", & RP, & num); sum = 0; int I; memset (DP, 0, sizeof (DP )); for (I = 0; I <num; I ++) {scanf ("% d % lf", & money [I], & RP [I]); sum = sum + money [I]; // use all the bank's money as the total volume of the backpack} DP [0] = 1; for (I = 0; I <num; I ++) zeroonepack (money [I], RP [I]); // The money in each bank is treated as an item volume for (I = sum; I> = 0; I --) // reverse search {If (DP [I] >=( 1-rp) {printf ("% d \ n", I); break ;}}} return 0 ;}