http://acm.uestc.edu.cn/#/problem/show/1218
Since the two-dimensional DP cannot be represented, add one dimension to indicate whether to place at the boundary, place one, two. There is a trick is if only put one, so long can.
WA has been so many times (embarrassing)
Start because L[I]/2 will appear decimal, did not notice, the length of all X2 can be solved.
WA again n times because did not notice j-l[i] without judgment, why not re it! Not happy ...
/*********************************************memory:1140 kbtime:3976 mslanguage:c++result:accepted************* /#include <iostream> #include <cstring>using namespace Std;typedef long Long Ll;int l[1005];int v[1005];ll dp[4005][5];int main () {int t; CIN >> T; int cas = 0; while (t--) {cas++; int n, L; CIN >> N >> L; L *= 2; ll ans = 0; for (int i = 0; i < n; ++i) {cin >> l[i] >> v[i]; L[i] *= 2; ans = max (ans, (LL) v[i]); } memset (DP, 0, sizeof DP); for (int i = 0, i < n; ++i) {for (int j = L; J >= L[i]/2;--j) {Dp[j ][2] = max (dp[j][2], dp[j-l[i]/2][1] + v[i]); if (J >= L[i]) dp[j][2] = max (dp[j][2], dp[j-l[i]][2] + v[i]); DP[J][1] = max (dp[j][1], dp[j-l[i]/2][0] + v[i]); if (J ≫= L[i]) dp[j][1] = max (dp[j][1], dp[j-l[i]][1] + v[i]); if (J >= L[i]) dp[j][0] = max (dp[j][0], dp[j-l[i]][0] + v[i]); }} ans = max (ans, dp[l][2]); cout << "Case #" << cas << ":" << ans << endl; } return 0;} /**input:502----------------
CCPC D-pick The Sticks (UESTC 1218) (01 backpack variants)