DFS count, five minutes if the answer is not updated, the solution is generally excellent.
#include <cstdio>#include<iostream>#include<string.h>#include<cstdlib>#include<algorithm>#include<queue>#include<vector>#include<cmath>#include<map>#include<stack>using namespacestd;int Constuu[4] = {1,-1,0,0};int Constvv[4] = {0,0,1,-1};typedefLong Longll;int ConstINF =0x3f3f3f3f; llConstINF =0x7fffffffffffffffll;DoubleEPS = 1e-Ten;DoublePI = ACOs (-1.0);#defineRep (i,s,n) for (int i= (s); i<= (n); ++i)#defineREP2 (i,s,n) for (int i= (s); i>= (n);-I.)#defineMem (v,n) memset (V, (n), sizeof (v))#defineLson L, M, rt<<1#defineRson m+1, R, rt<<1|1structnode{intx, y;} tempans[205],ans[205];Charfirst[101][101];BOOLvis[101][101];intBestscore;intSTEP;BOOLCheckCharmp[101][101],intXinty) {Rep (k,0,3){ intXx=x+uu[k], yy=y+Vv[k]; if(xx>=1&&xx<= -&& yy>=1&&yy<= -&& Mp[xx][yy]==mp[x][y])return true; } return false;}intColor1 (Charmp[101][101],BOOLvis[101][101],intXinty) {Vis[x][y]=true; intres=1; Rep (K,0,3){ intXx=x+uu[k], yy=y+Vv[k]; if(xx>=1&&xx<= -&& yy>=1&&yy<= -&& vis[xx][yy]==false&& Mp[xx][yy]==mp[x][y]) res+=Color1 (MP,VIS,XX,YY); } Mp[x][y]=0; returnRes;}voidProc1 (Charmp[101][101]) {Rep (J,1,Ten) Rep2 (I,9,1){ intG=i,h=J; while(g+1<=Ten&& mp[g+1][h]==0) ++G; MP[G][H]=Mp[i][j]; if(g!=i) mp[i][j]=0; } Rep (J,2,Ten){ if(mp[Ten][j]==0)Continue; intK; for(k=j-1; k>=1;--k)if(mp[Ten][k]!=0) Break; if(k +1<j) {Rep (i,1,Ten) {mp[i][k+1]=Mp[i][j]; MP[I][J]=0; } } }}voidprint () {Charms[101][101]; BOOLvs[101][101]; Mem (VS,false); Rep (I,1,Ten) Rep (J,1,Ten) ms[i][j]=First[i][j]; Rep (I,1,Ten) {Rep (J,1,Ten) if(ans[1].x==i&&ans[1].y==j) printf ("#"); Else{ if(ms[i][j]==0) printf (" "); Elseprintf ("%d", Ms[i][j]); } cout<<Endl; } Rep (I,1, STEP) {printf ("step%d = (%d,%d) \ n", I,ANS[I].X,ANS[I].Y); cout<<endl<<Endl; Color1 (MS,VS,ANS[I].X,ANS[I].Y); Proc1 (MS); if(i!=STEP) {Rep (k,1,Ten) {Rep (J,1,Ten) if(ans[i+1].x==k&&ans[i+1].y==j) printf ("#"); Else{ if(ms[k][j]==0) printf (" "); Elseprintf ("%d", Ms[k][j]); } cout<<Endl; } } }}//mp[][]:current State step:current step score:current scorevoidDfsCharmp[101][101],BOOLvis[101][101],intTxintTyintStepintscore) { //printf ("step=%d score=%d click on (%d,%d) of the last Image.\n", step,score,tx,ty); /*Rep (i,1,10) {Rep (j,1,10) if (mp[i][j]!=0) printf ("%d", mp[i][j]); else printf (""); cout<<endl; }*/tempans[step].x=TX; Tempans[step].y=Ty; Rep (I,1,Ten) Rep (J,1,Ten){ if(mp[i][j]==0)Continue;//This location is empty, skip if(Vis[i][j])Continue;//calculated, skipped if(check (mp,i,j) = =false){//Click this location to eliminate the blockvis[i][j]=true; Continue; } Chartemp_mp[101][101]; BOOLtemp_vis[101][101]; Mem (Temp_vis,false); Rep (I1,1,Ten) Rep (J1,1,Ten) temp_mp[i1][j1]=Mp[i1][j1]; intts=Color1 (TEMP_MP,VIS,I,J); Proc1 (TEMP_MP); DFS (Temp_mp,temp_vis,i,j,step+1, score+5*ts*ts); } if(score>Bestscore) {STEP=step; Rep (I,0, step) ans[i]=Tempans[i]; Bestscore=score; cout<<"Bestscore ="<<bestScore<<Endl; //print ();Rep (I,1, step) printf ("step%d = (%d,%d) \ n", I,ANS[I].X,ANS[I].Y); cout<<endl<<Endl; }}voidRead () {Rep (I,0,Ten) Rep (J,0,Ten) first[i][j]=-1; Freopen ("c:\\hello.in","R", stdin); Rep (I,1,Ten) Rep (J,1,Ten) scanf ("%d",&First[i][j]); Fclose (stdin);}voidinit () {Bestscore=0; Mem (VIS,false);}intMain () {read (); Init (); DFS (First,vis,-1,-1,0,0);}
Popstar Mobile game Machine Battle Program