题目大意:略
题目思路: 先求出一个最大匹配,再枚举每条边。(刚开始感觉好暴力...........但事实是只用了31ms 无语了)
#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. ",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; }