This question debug for up to 3 hours, ACM I can not give up, I came back to the first question!
Start thinking right, writing no, the result is more and more chaotic
Read the Code of a god on the Internet, learn a bit
/** Author:bingo * Created TIME:2015/3/2 21:23:20 * File Name:uva10118.cpp*/#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<string>#include<vector>#include<stack>#include<queue>#include<Set>#include<time.h>using namespacestd;Const intMaxint =-1u>>1;intdp[ $][ $][ $][ $];inta[4][ $];intf[5];intN;intans;intOkintIintJintPintq) { intm[ -]; memset (M,0,sizeof(m)); inttop=0; for(intt=0; t<i;t++) M[top++]=a[0][t]; for(intt=0; t<j;t++) M[top++]=a[1][t]; for(intt=0; t<p;t++) M[top++]=a[2][t]; for(intt=0; t<q;t++) M[top++]=a[3][t]; Sort (m,m+top); intCnt=0, tans=0; for(intt=0;t<top;) {if(m[t]==m[t+1]) {tans++; T+=2; }Else{cnt++; T++; } } if(cnt<=5) {ans=Max (Ans,tans); return 1; } return 0;}intDfsintIintJintPintq) { if(i==n&&j==n&&p==n&&q==n)return 0; if(i<N) {i++; if(OK (i,j,p,q)) {if(Dp[i][j][p][q]) {ans=Max (ans,dp[i][j][p][q]); DP[I][J][P][Q]=ans; }Else{dp[i][j][p][q]=Ans;dfs (i,j,p,q);} } } if(j<N) {J++; if(OK (i,j,p,q)) {if(Dp[i][j][p][q]) {ans=Max (ans,dp[i][j][p][q]); DP[I][J][P][Q]=ans; }Else{dp[i][j][p][q]=Ans;dfs (i,j,p,q);} } } if(p<N) {P++; if(OK (i,j,p,q)) {if(Dp[i][j][p][q]) {ans=Max (ans,dp[i][j][p][q]); DP[I][J][P][Q]=ans; }Else{dp[i][j][p][q]=Ans;dfs (i,j,p,q);} } } if(q<N) {Q++; if(OK (i,j,p,q)) {if(Dp[i][j][p][q]) {ans=Max (ans,dp[i][j][p][q]); DP[I][J][P][Q]=ans; }Else{dp[i][j][p][q]=Ans;dfs (i,j,p,q);} } }}intMain () { while(cin>>n&&N) { for(intI=0; i<n;i++) {cin>> a[0][i]>>a[1][i]>>a[2][i]>>a[3][i]; } memset (DP,0,sizeof(DP)); Ans=0; Memset (F,0,sizeof(f)); //OK (3,3,3,3);Dfs0,0,0,0); cout<< ans<<Endl; } return 0;}View Code
UVA 10118, Memory search