Topic Link: Portal
The main topic: there is a 3*n matrix, each lattice has a number, you can choose to merge into one of the adjacent two lattice, and the weight to two number product, if a number is not merged, the weight value becomes 0, the sum of the final weight value.
Topic idea: Compress in 2^3 state.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cmath>#include<algorithm>#include<cstring>#include<stack>#include<cctype>#include<queue>#include<string>#include<vector>#include<Set>#include<map>#include<climits>#defineLson Rt<<1,l,mid#defineRson Rt<<1|1,mid+1,r#defineFi first#defineSe Second#definePing (x, y) ((x-y) * (x-y))#defineMST (x, y) memset (x,y,sizeof (x))#defineMCP (x, y) memcpy (x,y,sizeof (y))using namespacestd;#defineGamma 0.5772156649015328606065120#defineMOD 1000000007#defineINF 0x3f3f3f3f#defineN 2000005#defineMAXN 100005typedef pair<int,int>Pii;typedefLong LongLL;intN,m,cnt,ans;inta[1005][5];intdp[1005][Ten];intDealintXintUinte) { for(intI=0;i<3; ++i)if((u& (1<<i) && (e& (1<<i)))return 0; inttemp=0; for(intI=0;i<3;++i) { if(e& (1<<i)) {Temp+=a[x-1][i+1]*a[x][i+1]; } } intt1=0, t2=0; E|=u; if((! (e&1) && (!) ( e&2)) t1=a[x][1]*a[x][2]; if((! (e&2) && (!) ( e&4)) t2=a[x][2]*a[x][3]; Temp+=Max (T1,T2); returntemp;}intMain () {intI,j,case=0; while(SCANF ("%d", &n)!=eof&&N) {MST (DP,0); for(i=1; i<=3; ++i) for(j=1; j<=n;++j) scanf ("%d",&A[j][i]); for(i=1; i<=n;++i) { for(j=0; j<=8;++j) for(intk=0; k<=8;++k) { inttemp=deal (I,J,K); DP[I][J]=max (dp[i][j],dp[i-1][k]+temp); }} ans=0; for(i=0; i<=8; ++i) ans=Max (ans,dp[n][i]); printf ("Case %d:%d\n",++Case,ans); } return 0;}
Uvalive 6560 the Urge to Merge