At least one of each layer, when rolling to a layer of illegal or not, so every time to memset
#include <bits/stdc++.h>#define REP (i,j,k) for (int i=j;i<=k;i++)#define RREP (i,j,k) for (int i=j;i>=k;i--)#define SCAN (a) scanf ("%d", &a)using namespaceStdConst intMAXN =5e5+11;Const intOO =0x3f3f3f3f;intN,m,k;typedefpair<int,int> p;vector<p> vec[ -];intdp[2][MAXN];intMain () { while(SCANF ("%d%d%d", &n,&m,&k)!=eof) {Rep (I,1, K) vec[i].clear (); Rep (I,1, N) {intA,b,c; scanf"%d%d%d", &a,&b,&c); Vec[a].push_back (P (b,c)); }BOOLflag=0; Rep (I,1Kif(!vec[i].size ()) flag=1;if(flag) {printf ("Impossible\ n");Continue; } Rep (I,0, m) dp[0][i]=0; Rep (I,1, K) {memset (dp[i&1],0x80,sizeofdp[i&1]);//Note when scrolling for(AutoK:vec[i]) {Rrep (J,m,k.first) {intC=k.first,w=k.second; dp[i&1][j]=max (dp[i&1][j],max (dp[i&1][j-c]+w,dp[i-1&1][J-C]+W)); } } }if(dp[k&1][m]<0) printf ("Impossible\ n");Elseprintf"%d\n",dp[k&1][m]); }return 0;}
HDU-3033 scrolling array with pits