标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2593 Accepted Submission(s): 1512
#include<iostream> #include<cstdio> #include<cstring> #include<string> using namespace std; int n,m,k,link[110],mark[110],g[110][110]; int x[110],y[110],sum,ans; bool dfs(int t) { for(int i=1;i<=m;i++) { if(mark[i]==-1&&g[t][i]) { mark[i]=1; if(link[i]==-1||dfs(link[i])) { link[i]=t; return true; } } } return false; } int main() { int cas=1; while(scanf("%d%d%d",&n,&m,&k)!=EOF) { sum=0,ans=0; memset(g,0,sizeof(g)); memset(link,-1,sizeof(link)); for(int i=1;i<=k;i++) { scanf("%d%d",&x[i],&y[i]); g[x[i]][y[i]]=1; } for(int i=1;i<=n;i++) { memset(mark,-1,sizeof(mark)); if(dfs(i)) sum++; } for(int i=1;i<=k;i++) { g[x[i]][y[i]]=0; int ret=0; memset(link,-1,sizeof(link)); for(int i=1;i<=n;i++) { memset(mark,-1,sizeof(mark)); if(dfs(i)) ret++; } if(ret<sum) ans++; g[x[i]][y[i]]=1; } printf("Board %d have %d important blanks for %d chessmen.\n",cas,ans,sum); cas++; } return 0; }
标签:
原文地址:http://www.cnblogs.com/a972290869/p/4248630.html