#include<bits/stdc++.h> using namespace std; int n, T, a[101][101], v[101], f[10010]; void solve (int d1, int d2) { memset(f, 0, sizeof(int) * (v[d1] + 1)); for (int i = 1; i <= n; i++) { int c = a[d1][i], w = a[d2][i]; for (int j = c; j <= v[d1]; j++) { f[j] = max (f[j], f[j - c] + w); } } int t = 0; for (int i = 0; i <= v[d1]; i++) t = max (t, v[d1] - i + f[i]); v[d2] = max (t, v[d2]); } int main() { ios::sync_with_stdio(false); cin >> T >> n >> v[0]; for (int i = 1; i <= T; i++) for (int j = 1; bj <= n; j++) cin >> a[i][j]; for (int i = 1; i <= T; i++) { v[i] = max (v[i], v[i - 1]); for (int j = i + 1; j <= T; j++) solve(i, j); } cout << v[T] << endl; return 0; }
标签:纪念品,int,2019csp,101,dp,d1 From: https://www.cnblogs.com/jacy1234/p/18379053