This is also a simple template application, but a bit different;
Important point: If you cancel this point, you cannot place as many pieces as possible, such as the original can put 3, if not put this can only put 2, indicating that it is an important point;
The problem of solving the idea is: first calculate the maximum number of matches, and then the reading can be placed in the coordinates of the point to cancel the mark, and then calculate the maximum match, if two matches the result is equal, indicating that it is not an important point, the number of records plus 1, count to remember to restore the mark;
At the end of the calculation, remember to use the maximum number of pieces to reduce the number of records;
The following code is attached:
1#include <iostream>2#include <string.h>3 using namespacestd;4 #defineMAXN 1055 intUN,VN;//Number of U,v6 intMAP[MAXN][MAXN];7 intLINKER[MAXN];8 BOOLUSED[MAXN];9 intX[MAXN],Y[MAXN];Ten BOOLDfsintU//find the augmented path from the left One { A intv; - for(v=1; v<=vn;v++)//This vertex number starts at 0 and needs to be modified starting from 1 - if(map[u][v]&&!Used[v]) the { -used[v]=true; - if(linker[v]==-1||DFS (Linker[v])) -{//find an augmented path, reverse +linker[v]=u; - return true; + } A } at return false;//don't forget it, always forget it. - } - intHungary () - { - intres=0; - intu; inmemset (linker,-1,sizeof(linker)); - for(u=1; u<=un;u++) to { +memset (Used,0,sizeof(used)); - if(Dfs (U)) res++; the } * returnRes; $ }Panax Notoginseng intMain () - { the intK,a,b,count,ans,res; + intt =1; A //freopen ("1281.txt", "R", stdin); the while(~SCANF (" %d%d%d",&un,&vn,&k)) + { -Count =0; $memset (Map,0,sizeof(map)); $ for(inti =0; I < K; i++) - { -scanf"%d%d",&a,&b); theMAP[A][B] =1; -X[i] = A;y[i] =b;Wuyi } the intAns =Hungary (); - for(inti =0; i < K; i++) Wu { -Map[x[i]][y[i]] =0; Aboutres =Hungary (); $ if(res = =ans) -Count + +; -Map[x[i]][y[i]] =1; - } Aprintf"Board%d has%d important blanks for%d chessmen.\n", t++,k-Count,ans); + the } - return 0; $}
View Code
hdu1281 board Game