标签:
题目大意:略
#include<stdio.h> #include<string.h> #include<algorithm> #include<iostream> using namespace std; #define maxn 1500 bool G[maxn][maxn], vis[maxn]; int P[maxn]; int n, m, cas = 1; bool Find(int u) { for(int i=1; i<=m; i++) { if(G[u][i] && !vis[i]) { vis[i] = true; if(P[i] == -1 || Find(P[i]) ) { P[i] = u; return true; } } } return false; } int GetAns() { memset(P, -1, sizeof(P)); int ans = 0; for(int i=1; i<=n; i++) { memset(vis, false, sizeof(vis)); if( Find(i) ) ans ++; } return ans; } void solve() { int Imp = 0, ans; ans = GetAns(); for(int i=1; i<=n; i++) { for(int j=1; j<=m; j++) { if(!G[i][j]) continue; G[i][j] = false; if(GetAns() < ans) Imp ++; G[i][j] = true; } } printf("Board %d have %d important blanks for %d chessmen.\n",cas ++, Imp, ans); } int main() { int Q; while(scanf("%d %d %d",&n, &m, &Q) != EOF) { memset(G, false, sizeof(G)); while(Q --) { int a, b; scanf("%d %d", &a, &b); G[a][b] = true; } solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/chenchengxun/p/4718577.html