Hdu4800_joseph Phina and RPG (two-dimensional dp)
Question: The dp state is set to Use Role j to pass the maximum percentage of I (dp [I] [j])
Start with the last field:
Dp [I] [j] = rate [j] [AI [I] * max (dp [I + 1] [j], dp [I + 1] [a [I]);
That is, the maximum winning rate of using role j to pass the I-level = the winning rate of using role j to win the I-level AI * max (the probability of using j for customs clearance in the next level, the probability that AI passes through the next mark)
Set the initial value and review it.
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
# Include
Using namespace std; # define mem (x, y) memset (x, y, sizeof (x) inline int lowbit (int x) {return x & (-x );} typedef long int LL; const int INF = 0x3f3f3f3f; const long double PI = acos (0.0) * 2.0; const int N = 10000 + 10; const double eps = 1e-6; double dp [N] [200], rate [200] [200]; int ai [N]; int Comb (int x, int y); int main () {int n, m; // ios: sync_with_stdio (false); // close the synchronous stream while (scanf (% d, & m) = 1) {int r = Comb (m, 3); for (int I = 0; I <r; I ++) for (int j = 0; j <r; j ++) scanf (% lf, & rate [I] [j]); scanf (% d, & n); for (int I = 0; I <n; I ++) scanf (% d, & ai [I]); mem (dp, 0.0); for (int j = 0; j <r; j ++) dp [n-1] [j] = rate [j] [ai [n-1]; for (int I = n-2; I> = 0; I --) {for (int j = 0; j <r; j ++) {dp [I] [j] = max (dp [I] [j], rate [j] [ai [I] * max (dp [I + 1] [j], dp [I + 1] [ai [I]);} double res = 0.0; for (int j = 0; j <r; j ++) res = max (res, dp [0] [j]); printf (%. 6lf, res) ;}return 0 ;}int Comb (int x, int y) {int u = 1, v = 1, len; if (y = 0 | x = y) return 1; if (y = 1) return x; if (x <y) return 0; if (y> x/2) y = len = x-y; else len = y; while (len --) {u * = x --; v * = y --;} return (int) (u/v );}