HDU 2955 Robberies (conversion probability-01 backpack)
Code:
/** Problem: HDU No. 2955 * Running time: 46 MS * Complier: G ++ * Author: ACM_herongwei * Create Time: PM on March 9, X zeroonebags * use the probability of successful escape as a value! The total amount of money in the bank is used as the capacity of the backpack! The amount of money in a single bank, and then zeronebags */# include
# Include
# Include
# Include # define CLR (c, v) (memset (c, v, sizeof (c) using namespace std; template
Inline _ T Max (_ T a, _ T B) {return (a> B )? (A) :( B);} template
Inline _ T Maxx (_ T a, _ T B, _ T c) {return (a> Max (B, c ))? (A) :( Max (B, c);} const int N = 1e4 + 10; double dp [N]; int volume [N]; double p_value [N]; int main () {int Ncase; scanf (% d, & Ncase); while (Ncase --) {CLR (dp, 0); CLR (volume, 0 ); CLR (p_value, 0); double P; int n_banks; int sum_v = 0; scanf (% lf % d, & P, & n_banks); P = 1.0-P; // escape probability for (int I = 0; I
= Volume [I]; -- j) {if (dp [j] <= dp [j-volume [I] * p_value [I]) // note that it is multiplied! {Dp [j] = dp [j-volume [I] * p_value [I] ;}} int I; for (I = sum_v; I >= 0; -- I) // calculate the probability from the forward of the total value {if (dp [I]> = P) {break ;}} printf (% d, I );} return 0;}/* 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 ouput246 */