首页 > 其他 > 详细

棋盘游戏 HDU - 1281

时间:2020-03-04 17:52:59      阅读:50      评论:0      收藏:0      [点我收藏+]
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int maxn = 1e4+5;
int G[105][105];
int a[maxn],b[maxn];
int match[105];
int st[105];
int n,m,ans;
bool find(int u) {
    for(int i = 1; i<=m; i++) {
        if(!st[i]&&G[u][i]) {
            st[i] = 1;
            if(!match[i]||find(match[i])) {
                match[i] = u;
                return true;
            }
        }
    }
    return false;
}
int Count() {
    int ans = 0;
    memset(match,0,sizeof(match));
    for(int i =0; i<=n; i++) {
        memset(st,0,sizeof(st));
        if(find(i)) 
            ans++;
    }
    return ans;
}
int main() {
    int k;
    int Case = 0;
    while(cin>>n>>m>>k) {
        memset(G,0,sizeof(G));
        for(int i = 0; i<k; i++) {
            cin>>a[i]>>b[i];
            G[a[i]][b[i]] = 1;
        }
        ans = 0;
        //先求最大匹配 
        int num = Count();
        //然后依次去掉每一条边,判断是不是会减少 
        for(int i =0; i<k; i++) {
            G[a[i]][b[i]] = 0;
            if(Count()<num) 
                ans++;
            G[a[i]][b[i]] = 1;
        }
        printf("Board %d have %d important blanks for %d chessmen.\n",++Case,ans,num);
    }
}

棋盘游戏 HDU - 1281

原文:https://www.cnblogs.com/QingyuYYYYY/p/12410811.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!