标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2757 Accepted Submission(s): 1612
删边直接匈牙利算法求最大匹配,如果变小,那么说明这个位置符合条件
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> using namespace std; int n,m,k,mark[105],mp[105][105],link[105]; struct node { int x,y; }e[105]; bool dfs(int x) { for(int i=1;i<=m;i++) { if(mp[x][i]&&mark[i]==-1) { mark[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=x; return true; } } } return false; } int main() { int cas=1; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { int cnt=0; memset(mp,0,sizeof(mp)); for(int i=1;i<=k;i++) { scanf("%d%d",&e[i].x,&e[i].y); mp[e[i].x][e[i].y]=1; } int maxx=0; memset(link,-1,sizeof(link)); for(int i=1;i<=n;i++) { memset(mark,-1,sizeof(mark)); if(dfs(i)) maxx++; } for(int i=1;i<=k;i++) { int ans=0; mp[e[i].x][e[i].y]=0; memset(link,-1,sizeof(link)); for(int i=1;i<=n;i++) { memset(mark,-1,sizeof(mark)); if(dfs(i)) ans++; } mp[e[i].x][e[i].y]=1; if(ans<maxx) cnt++; } printf("Board %d have %d important blanks for %d chessmen.\n",cas++,cnt,maxx); } return 0; }
标签:
原文地址:http://www.cnblogs.com/water-full/p/4459691.html