Tag: color a ring class coordinate STD for span ret
Dual Line DP
#include <iostream>#include<algorithm>#include<ctype.h>#include<string>#include<string.h>#include<vector>#include<queue>using namespacestd;intdp[ the][ -][ -];//compressed space dp[x1+y1][x1][x2]; //values known as X1+Y1, X1, and x2, combined with x1 + y1 = x2 + y2 can determine x1,y1,x2,y2 four valuesintmp[ -][ -];intMaxintAintBintCintd) { if(a>=b && a>=c && a>=d)returnA; Else if(B>=a && b>=c && b>=d)returnb; Else if(C>=a && c>=b && c>=d)returnC; Else if(D>=a && d>=c && d>=b)returnD;}intMain () {intT; CIN>>T; while(t--) { intM,n; CIN>>m>>N; for(intI=1; i<=m;i++) { for(intj=1; j<=n;j++) {cin>>Mp[i][j]; } } intK,x1,y1,x2,y2; for(k=0; k<=m+n;k++) for(x1=0; x1<=m;x1++) for(x2=0; x2<=m;x2++) dp[k][x1][x2]=0; for(k=2; k<=m+n;k++) { for(x1=1; x1<=m;x1++)//(x, y) as one of the coordinates, with K to find the corresponding other point, traverse K and all (x, y) can get all the values of Dp[k][x][y] { for(x2=1; x2<=m;x2++) {y1= K-X1; Y2= K-x2; if(y1<=n && y2<=n && y1>=1&& y2>=1)//no cross-border { if(x1! = x2 && y1! = y2)//do not intersect { intV1 = dp[k-1][x1-1][x2-1] + Mp[x1][y1] +Mp[x2][y2]; intV2 = dp[k-1][X1][X2] + mp[x1][y1] +Mp[x2][y2]; intV3 = dp[k-1][x1-1][X2] + mp[x1][y1] +Mp[x2][y2]; intV4 = dp[k-1][x1][x2-1] + Mp[x1][y1] +Mp[x2][y2]; DP[K][X1][X2]=Max (V1,V2,V3,V4); } }}} cout<<dp[m+n-1][m][m-1]<<Endl; } return 0;}
Nyoj 61 Pass the note (a)