3 3 4 1 2 1 3 2 1 2 2 3 3 4 1 2 1 3 2 1 3 2
Board 1 have 0 important blanks for 2 chessmen. Board 2 have 3 important blanks for 3 chessmen.
题解:首先建图,求出行->列的最大匹配ans。然后依次删除节点,如果此时的最大匹配小于ans,说明该点是必须要放的,即为重要点。
ACcode:
#include<cstring> #include<cstdio> #include<iostream> #include<algorithm> #include<cmath> #include<vector> #define N 111 using namespace std; int n,m,k; int maze[N][N]; int linker[N]; bool mp[N][N]; bool used[N]; int vN,uN; bool dfs(int u) { int v; for(v=1; v<=m; v++) if(maze[u][v]&&!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } return false; } int hungary() { int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=1; u<=n; u++) { memset(used,0,sizeof(used)); if(dfs(u)) res++; } return res; } int x[10100],y[10100]; int main() { // freopen("in.txt","r",stdin); int ca=1; while(~scanf("%d%d%d",&n,&m,&k)) { memset(maze,0,sizeof maze); for(int i=0; i<k; i++) { scanf("%d%d",&x[i],&y[i]); maze[x[i]][y[i]]=1; } int ans=hungary(); int cnt=0; for(int i=0; i<k; i++) { maze[x[i]][y[i]]=0; if(ans>hungary()) cnt++; maze[x[i]][y[i]]=1; } printf("Board %d have %d important blanks for %d chessmen.\n",ca++,cnt,ans); } return 0; }
原文地址:http://blog.csdn.net/acm_baihuzi/article/details/45728059