! Hdu 1203 -- dp -- (deep understanding), hdu1203 -- dp --
James has n yuan. He wants to apply for a foreign school and apply for the si fee for the I-th school. The probability of successful application is pi, the probability that James can apply for at least one school.
Analysis: the probability is, of course, the minimum value from the opposite side. State transition equation: dp [I] = min (dp [j] * p [I], dp [I]). I think wrong, I traverse according to the previous dp routine according to the array, and sorted first. dp [I] represents the optimal solution when applying for the I school; the correct solution should be based on the cost. dp [I] indicates the optimal solution when I yuan is used. This is the correct idea.
Dp should be further understood!
Code:
# Include <iostream> # include <cstdio> using namespace std; int n, m; int a [10008]; double p [10008], dp [10008]; double DP () {double mi = 1; for (int I = 0; I <m; I ++) {for (int j = n; j-a [I]> = 0; j --) {if (dp [j]> dp [j-a [I] * p [I]) dp [j] = dp [j-a [I] * p [I]; if (mi> dp [j]) mi = dp [j];} return mi;} int main () {while (cin> n> m) {if (! N &&! M) break; for (int I = 0; I <m; I ++) {cin> a [I]> p [I]; p [I] = 1-p [I];} for (int I = 0; I <= n; I ++) dp [I] = 1; double ans = DP (); printf ("% 0.1lf % \ n", 100 * (1-ans ));}}