Check count (1)
Time limit:10000/5000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 5961 Accepted Submission (s): 2268
Problem description gives you a n*n checkered checkerboard with a non-negative number in each lattice.
Take out a number of the number, so that any of the two number of the lattice does not have a common edge, that is, the number of the 2 lattice is not adjacent, and the number of the largest.
Input includes multiple test instances, each of which consists of an integer n and n*n non-negative numbers (N<=20)
Output for each test instance, the maximum possible and
Sample Input375 15 21 75 15 28 34 70 5
The Output188 of the maximum point weight independent set of the Sample for the EK algorithm
/************************************************author: Hart 13Created TIME:2015/1/7 23:38:02file Name:hdu 1565 squares Fetch number (1). cpp*************************************************/#include<iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<vector>#include<queue>#include<Set>#include<string>#include<cmath>#include<cstdlib>#include<ctime>using namespacestd;#defineINF 0x3f3f3f3f#definell Long Long#defineN 510intN;intsrc;intdes;intsum;intPre[n];intMpt[n][n];intMap[n][n];intdir[4][2]={1,0,-1,0,0,1,0,-1};queue<int>Q;BOOLBFs () { while(!q.empty ()) Q.pop (); memset (PRE,-1,sizeof(pre)); PRE[SRC]=0; Q.push (SRC); while(!Q.empty ()) { intu=Q.front (); Q.pop (); for(intv=0; v<=n*n+1; v++) { if(pre[v]==-1&& mpt[u][v]>0) {Pre[v]=u; if(V==des)return 1; Q.push (v); } } } return 0;}intEK () {intmaxflow=0; while(BFS ()) {intminflow=INF; for(intI=des;i!=src;i=Pre[i]) Minflow=min (minflow,mpt[pre[i]][i]); Maxflow+=Minflow; for(intI=des;i!=src;i=Pre[i]) {Mpt[pre[i]][i]-=Minflow; Mpt[i][pre[i]]+=Minflow; } } returnMaxflow;}intMain () {inti,j,k; while(SCANF ("%d", &n)! =EOF) {Sum=0; memset (MPT,0,sizeof(MPT)); for(i=1; i<=n;i++) { for(j=1; j<=n;j++) {scanf ("%d",&Map[i][j]); Sum+=Map[i][j]; }} src=0; Des=n*n+1; for(i=1; i<=n;i++) { for(j=1; j<=n;j++) { if((i+j)%2==0) mpt[src][(I-1) *n+j]=Map[i][j]; Elsempt[(I-1) *n+j][des]=Map[i][j]; } } for(i=1; i<=n;i++) { for(j=1; j<=n;j++) { if((i+j)%2==0) { for(k=0;k<4; k++) { intx=i+dir[k][0]; inty=j+dir[k][1]; if(x>=1&& x<=n && y>=1&& y<=N) {mpt[(i-1) *n+j][(x1) *n+y]=INF; } }}}} printf ("%d\n", sum-EK ()); } return 0;}
Network stream [HDU 1565] Box fetch number (1)