标签:
#include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; bool mp[110][110]; bool visit[110]; int match[110]; int n,m; int dfs(int i) { for(int j = 1;j<=m;j++) { if(visit[j]||!mp[i][j]) continue; visit[j] = 1; int q = match[j]; match[j] = i; if(q == 0||dfs(q)) return 1; match[j] = q; } return 0; } int main() { int k,i,j,z = 0; while(cin>>n>>m>>k) { z++; memset(mp,0,sizeof(mp)); for(i = 0;i<k;i++) { int a,b; scanf("%d%d",&a,&b); mp[a][b] = 1; } int sum = 0; memset(match,0,sizeof(match)); for(i = 1;i<=n;i++) { memset(visit,0,sizeof(visit)); sum += dfs(i); } int num = 0; for(i = 1;i<=n;i++) { for(j = 1;j<=m;j++) { if(!mp[i][j]) continue; mp[i][j] = 0; int tsum = 0; memset(match,0,sizeof(match)); for(int t = 1;t<=n;t++) { memset(visit,0,sizeof(visit)); tsum += dfs(t); } if(tsum!=sum) num++; mp[i][j] = 1; } } printf("Board %d have %d important blanks for %d chessmen.\n",z,num,sum); } return 0; }
标签:
原文地址:http://www.cnblogs.com/wos1239/p/4466251.html