See the range basically can think of DP, handling a little trouble
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <string>5#include <algorithm>6#include <map>7#include <queue>8#include <stack>9#include <cmath>Ten#include <vector> One #defineINF 0x3f3f3f3f A #defineINF 0X3FFFFFFFFFFFFFFFLL - #defineEPS 1e-9 - #definePi ACOs (-1.0) the using namespacestd; -typedefLong Longll; - //Edges[i][j] is the number of the Edge (I,J), Marks[i] Indicates whether edge I is a horizontal or vertical edge - intedges[ -][ -],marks[ -],p[ -]; + //Cont[i] is the number of bits in the state after which the edge is added, Conp[i] is the next state where I bit is - intdp[ the],cont[ -],conp[ -],len; + //Selected[i] Indicates whether the first edge is selected at the beginning. A BOOLselected[ -]; at voidInit () - { - intCnt=0; -memset (Edges,0,sizeof(edges)); -Memset (Marks,0,sizeof(marks)); -Memset (selected,0,sizeof(selected)); in for(intI=0;i< the; ++i) dp[i]=-inf; - for(intI=1; i<= -; i+=4) to { + for(intj=0;j<3;++j) - { theedges[i+j][i+j+1]=edges[i+j+1][i+j]=++CNT; *marks[cnt]=1; $ }Panax Notoginseng if(i== -) Break; - for(intj=0;j<4;++j) theedges[i+j][i+j+4]=edges[i+j+4][i+j]=++CNT; + } A for(intI=0;i< -; ++i) p[i]=1<<i; the } +InlineBOOLCheckintAintBintCintState ) - { $ if(!selected[a]&& (p[cont[a]]&state) = =0)return false; $ if(!selected[b]&& (p[cont[b]]&state) = =0)return false; - if(!selected[c]&& (p[cont[c]]&state) = =0)return false; - return true; the } - intGetpoints (intEintNow )Wuyi { the intsum=0; - inta,b,c; Wu if(Marks[e]) - { Abouta=e-4; b=e-3; c=e-7; $ if(c>0&&Check (a,b,c,now)) -sum++; -A=e+3; b=e+4; c=e+7; - if(a< -&&Check (a,b,c,now)) Asum++; + } the Else - { $a=e-4; b=e-1; c=e+3; the if(marks[c]&&Check (a,b,c,now)) thesum++; thea=e-3; b=e+1; c=e+4; the if(marks[a]&&Check (a,b,c,now)) -sum++; in } the returnsum; the } About intFintState ) the { the if(state==p[len]-1)return 0; the if(Dp[state]!=-inf)returnDp[state]; +dp[state]=0; - inttmp=-inf; the for(intI=0; i<len;++i)Bayi { the if((p[i]&state) = =0) theTmp=max (Tmp,getpoints (Conp[i],state)-F (p[i]|State )); - } - returndp[state]=tmp; the } the intMain () the { the //freopen ("In.txt", "R", stdin); - //freopen ("OUT.txt", "w", stdout); the intT,tcase=0; thescanf"%d",&t); the while(t--)94 { thetcase++; the Init (); the intn,a,b,e,ans=0, turns=0;98scanf"%d",&n); Aboutlen= --N; - for(intI=0; i<n;++i)101 {102scanf"%d%d",&a,&b);103E=Edges[a][b];104 if(turns) theAns-=getpoints (E,0);106 ElseAns+=getpoints (E,0);107turns^=1;108selected[e]=true;109 } the intCnt=0;111 for(intI=1; i<= -;++i) the if(!selected[i]) {conp[cnt]=i;cont[i]=cnt;cnt++;}113 if(turns) theAns-=f (0); the ElseAns+=f (0); theprintf"Case #%d:", tcase);117 if(ans>0) puts ("Tom200");118 ElsePuts"Jerry404");119 } - return 0;121}
Hdu 4753 2013 Nanjing Division online Race Memory Search * * * * *