For the first time, the probability is regarded as a backpack, which is increased by 100000 times. In addition, the probability of many strong banks is multiplied, not the sum.
Take the amount of money you want to grab as a backpack transfer formula:
DP [J] indicates the maximum probability of success when the user can grab J million
DP [J] = max (DP [J], DP [J-M [I] * (1-p_bank [I]);
/*************************************** * *********************************> File Name: hdu2955.cpp> author: Yang> mail: [email protected]> created time: saturday, August 23, 2014 10:57:47 ************************************* * *********************************/# include <iostream> # include <stdio. h> # include <memory. h> using namespace STD; # define n 105int main () {// freopen ("in.txt", "r", stdin); int t, n; double DP [1, 10010]; cin> T; int M [N]; double p_bank [N], p_thief; while (t --) {CIN> p_thief> N; int sum = 0; for (INT I = 0; I <n; I ++) {CIN> M [I]> p_bank [I]; sum + = m [I];} memset (DP, 0, sizeof (DP); DP [0] = 1; for (INT I = 0; I <n; I ++) {for (Int J = sum; j> = m [I]; j --) {DP [J] = max (DP [J], DP [J-M [I] * (1-p_bank [I]) ;}} for (INT I = sum; I> = 0; I --) {If (DP [I]> (1-p_thief) {printf ("% d \ n", I); break ;}}}}
HDU robberies 2955 01 backpack