int dp[MAX][MAX][MAX][MAX]; int n, m, a[MAX][MAX];
inlineintgetint(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
inlinevoidputint(int x, bool returnValue){ if (x < 0) { x = -x; putchar('-'); } if (x >= 10) putint(x / 10, false); putchar(x % 10 + '0'); if (returnValue) putchar('\n'); }
intmain(int argc, char *const argv[]){ m = getint(), n = getint(); for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { a[i][j] = getint(); } } for (int i = 1; i <= m; ++i) { for (int j = 1; j <= n; ++j) { for (int k = 1; k <= m; ++k) { for (int l = j + 1; l <= n; ++l) { dp[i][j][k][l] = std::max(std::max(dp[i-1][j][k-1][l], dp[i-1][j][k][l-1]), std::max(dp[i][j-1][k-1][l], dp[i][j-1][k][l-1])) + a[i][j] + a[k][l]; } } } } putint(dp[m][n-1][m-1][n], true); return0; }
inlineintgetint(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
inlinevoidputint(int x, bool returnValue){ if (x < 0) { x = -x; putchar('-'); } if (x >= 10) putint(x / 10, false); putchar(x % 10 + '0'); if (returnValue) putchar('\n'); }
intmain(int argc, char *const argv[]){ n = getint(), m = getint(); dp[0][1] = 1; for (int i = 1; i <= m; ++i) { dp[i][1] = dp[i-1][2] + dp[i-1][n]; dp[i][n] = dp[i-1][1] + dp[i-1][n-1]; for (int j = 2; j < n; ++j) { dp[i][j] = dp[i-1][j-1] + dp[i-1][j+1]; } } putint(dp[m][1], true); return0; }
structFood { int Volume; int Weight; int Calories; } food[MAXN];
inlineintgetint(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
inlinevoidputint(int x, bool newLine){ if (x < 0) x = -x; if (x >= 10) putint(x / 10, false); putchar(x % 10 + '0'); if (newLine) putchar('\n'); }
intmain(int argc, char *const argv[]){ maxVolume = getint(); maxWeight = getint(); n = getint(); for (int i = 1; i <= n; ++i) { food[i].Volume = getint(); food[i].Weight = getint(); food[i].Calories = getint(); } for (int i = 1; i <= n; ++i) { for (int j = maxVolume; j >= food[i].Volume; --j) { for (int k = maxWeight; k >= food[i].Weight; --k) { f[j][k] = std::max(f[j][k], f[j - food[i].Volume][k - food[i].Weight] + food[i].Calories); } } } printf("%d\n", f[maxVolume][maxWeight]); return0; }
inlineintgetint(){ int s = 0, x = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') x = -1; ch = getchar(); } while (isdigit(ch)) { s = s * 10 + ch - '0'; ch = getchar(); } return s * x; }
inlinevoidputint(int x, bool returnValue){ if (x < 0) { x = -x; putchar('-'); } if (x >= 10) putint(x / 10, false); putchar(x % 10 + '0'); if (returnValue) putchar('\n'); }
intmain(int argc, char *const argv[]){ n = getint(), m = getint(), T = getint(); for (int i = 1; i <= n; ++i) { d[i].time = getint(); d[i].cost = getint(); } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { for (int k = 1; k <= T; ++k) { if (j >= d[i].time && k >= d[i].cost) { dp[i][j][k] = std::max(dp[i-1][j][k], dp[i-1][j - d[i].time][k - d[i].cost] + 1); } else { dp[i][j][k] = dp[i-1][j][k]; } } } } putint(dp[n][m][T], __RETURN); return0; }