Title Description
Description
Give a n*n (n<=100) chess board, in which some points were removed and asked how many 1*2 dominoes could be used to cover up.
Enter a description
Input Description
First Behavior n,m (indicates a lattice with M delete)
The second line to m+1 acts X, Y, respectively, indicating where the delete lattice is located
X is line X
Y is the nth column
Output description
Output Description
A number, that is, the maximum number of overlay cells
Sample input
Sample Input
8 0
Sample output
Sample Output
32
Data range and Tips
Data Size & Hint
Classic Questions
#include <iostream>#include<cstdio>#include<string>#include<cstring>#include<vector>#include<queue>#include<algorithm>#defineMAXN 105#define__maxnodes 13145using namespacestd;//the number of vertices and edges starts at 0//adjacency Table StorageVector<int> G[__maxnodes];/*G[i] Stores the number of edges on which vertex I departs*/typedef vector<int>:: iterator iterator_t;intNum_nodes;intNum_left;intNum_right;intnum_edges;intMatching[__maxnodes];/*Storage Solution Results*/intCheck[__maxnodes];intn,m,rec[maxn][maxn],cnt;intdx[4] = {-1,0,1,0};intdy[4] = {0,-1,0,1};BOOLJudgeintYintx) { if(X <1|| X > N | | Y <1|| Y > N | | REC[Y][X])return false; Else return true;}BOOLDfsintu) { for(iterator_t i = G[u].begin (); I! = G[u].end (); ++i) {//for each adjacency point of U intv = *i; if(!check[v]) {//requirements are not on alternate routesCHECK[V] =true;//put on Alternate road if(Matching[v] = =-1||DFS (Matching[v])) { //if it is an open point, it indicates that the alternate route is an augmented path, then the route is switched and the success is returnedMATCHING[V] =u; Matching[u]=v; return true; } } } return false;//There is no augmented path, return failure}intHungarian () {intAns =0; memset (Matching,-1,sizeof(matching)); for(intu=0; U < Num_left; ++u) {if(Matching[u] = =-1) {memset (check,0,sizeof(check)); if(DFS (u))++ans; } } returnans;}intMain () {CIN>>n>>m; intx, y; for(inti =1; I <= m;i++) {scanf ("%d%d",&y,&x); REC[Y][X]=1; } intCU,CV; for(inti =1; I <= n;i++){ for(intj =1; J <= n;j++){ if(Rec[i][j])Continue; for(intK =0; k <4; k++){ intNY = i +Dy[k]; intNX = j +Dx[k]; if(judge (Ny,nx)) {cu= (I-1) *n+j-1; CV= (ny-1) *n+nx-1; G[cu].push_back (CV); } }}} Num_left= NN; cout<<Hungarian (); return 0;}
CODEVS2171 Board Overlay