Valley 1156 Garbage Trap
#include <bits/stdc++.h>#defineINF 1000000007using namespacestd;intD,g,ans;BOOLF;structsd{intt,f,h;BOOL operator< (ConstSD q)Const{returnt<q.t;};} s[1009];intdp[2][109],q[109];intMain () {scanf ("%d%d",&d,&g); for(intI=1; i<=g;i++) {scanf ("%d%d%d",&s[i].t,&s[i].f,&s[i].h);} Sort (S+1, s+g+1); for(intj=0; j<= the; j + +) dp[0][j]=-inf;dp[0][0]=Ten; S[g+1].t=Inf;memset (q,-1,sizeof(q)); for(intI=1; i<=g;i++){ for(intj=0; j<= the; j + +) {q[j+s[i].h]=max (dp[(i-1) &1][j],q[j+s[i].h]); Q[J]=max (q[j],dp[(i-1) &1][j]+s[i].f);} F=0; for(intj=d;j<= the; j + +){if(q[j]>=0) {printf ("%d\n", s[i].t);return 0;}} for(intj=0; j<= the; j + +) {Dp[i&1][J]=Q[J];if(q[j]>=s[i+1].T) f=1;Elsedp[i&1][j]=-inf;}if(!f) { for(intj=0; j<= the; j + +)if(Ans<q[j]) ans=Q[j];p rintf ("%d\n", ans);return 0;} memset (q,-1,sizeof(q));} for(intI=1; i<= the; i++){if(dp[g&1][i]>ans) ans=dp[g&1][i];} printf ("%d\n", ans);return 0;}
Luo gu 1019 word solitaire
No complexity proof, and a random set of data can t fly
#include <bits/stdc++.h>using namespacestd;intn,to[ A][ A],ans,vis[ A];Chars[ A][ +];BOOLf=0;voidDfsintBintx) { if(X>ans) ans=x; for(intI=1; i<=n;i++){ if(to[b][i]&& (vis[i]<2) ) {Vis[i]++; DFS (i,x+strlen (S[i])-To[b][i]); Vis[i]--; } }}intMain () {scanf ("%d",&N); for(intI=1; i<=n;i++) {scanf ("%s", S[i]); } scanf ("%s", s[0]); for(intI=0; i<=n;i++){ for(intj=0; j<=n;j++){ for(intK=strlen (S[i])-1; k>=0; k--) {f=0; for(intQ=k;q<strlen (S[i]); q++){ if(S[i][q]!=s[j][q-k]) f=1; } if(!f) {To[i][j]=strlen (S[i])-K; Break; } }}} vis[0]=2; DFS (0,1); printf ("%d\n", ans); return 0;}
"bzoj1600" [Usaco2008 Oct] Building Fences
#include <bits/stdc++.h>using namespacestd;intn,dp[2005][5];intMain () {Freopen ("x.in","R", stdin); Freopen ("X1.out","W", stdout); scanf ("%d",&N); dp[1][1]=1;ints=n/2;if(n%2) s++; for(intI=2; i<=n;i++) for(intj=1; j<=4; j + +) {Dp[i][j]=dp[i-1][j]+dp[i-1][j-1]; if(I>= (s+j-1) &&j>1) dp[i][j]-=dp[i-s][j-1]; if(I>= (s+j-1) &&j==1) dp[i][j]--; if(dp[i][j]<0) dp[i][j]=0; } printf ("%d\n", dp[n][4]); return 0;}
The river crossing crossing problem of "bzoj1617" river
#include <bits/stdc++.h>#defineMAXN 2505#defineINF 10000000000000000#definell Long Long//Remember to look at the rangeusing namespaceStd;ll N,M[MAXN],DP[MAXN];intMain () {scanf ("%lld%lld", &n,&m[0]); for(intI=1; i<=n;i++) {scanf ("%lld",&M[i]); M[i]+=m[i-1];DP [i]=inf; } dp[0]=0; for(intI=0; i<=n;i++){ for(intj=1; j+i<n;j++) {Dp[i+j]=min (dp[i+j],dp[i]+m[j]+m[0]); } Dp[n]=min (dp[n],dp[i]+m[n-i]); } printf ("%lld\n", Dp[n]);}
bzoj3791 Job
#include <bits/stdc++.h>using namespacestd;intn,dp[2][155][2],k,ans;intMain () {scanf ("%d%d", &n,&k);intA;SCANF ("%d",&a); dp[1][1][a]=1; for(intp=0, q=1, i=1; i<n;i++, Swap (P,Q)) {scanf ("%d",&a); for(intj=1; j<=2*k-1; j + +) for(intx=0;x<2; x + +) for(inty=0;y<2; y++) {dp[p][j+ (x!=y)][y]=max (dp[q][j][x]+ (y==a), dp[p][j+ (x!=y)] [y]); //remember to put the same in front and change your code before you think about it. } for(intj=1; j<=2*k-1; j + +) {ans=max (ans,dp[p][j][0]); Ans=max (ans,dp[p][j][1]); dp[q][j][0]=dp[q][j][1]=0; }} printf ("%d\n", ans); return 0;}
DP1, tomorrow.