The test is always thinking that the first dimension is to go to the maximum value of I time, and then did not consider that this can calculate the number of each card used ....
Dp[i][j][k][l] means the first card with I, the second card with J, the third card with K, the fourth card with L-sheet maximum
#include <cstdio> #include <iostream> #define MAXN 355using namespace Std;int c[5],a[maxn],f[41][41][41][41 ];int N,m;int Main () {scanf ("%d%d", &n,&m), int x;for (int i = 1; I <= n; i++) scanf ("%d", &a[i]); for (int i = 1; I <= m; i++) {scanf ("%d", &x); c[x]++;} F[0][0][0][0] = a[1];f[1][0][0][0] = a[2];f[0][1][0][0] = a[3];f[0][0][1][0] = a[4];f[0][0][0][1] = a[5];for (int i = 0; i <= C[1]; i++) for (int j = 0; J <= C[2]; + j) for (int k = 0, K <= c[3]; k++) for (int l = 0; l <= c[4]; l++) {int w = I,x = J,y = K,z = L;if (w! = 0) W = f[i-1][j][k][l];if (x! = 0) x = f[i][j-1][k][l];if (Y! = 0) y = f[i][j][k-1][l];if (Z! = 0) z = f[i] [j] K [L-1];int t = max (W,max (X,max (y,z))); F[i][j][k][l] = t + a[1+i+2*j+3*k+4*l];} printf ("%d\n", F[c[1]][c[2]][c[3]][c[4]]);}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
NOIP2010 Turtle Chess (multidimensional DP)