hdu1498 二分图匹配(多次最小点覆盖)

来源:互联网 发布:js 判断span 是否隐藏 编辑:程序博客网 时间:2024/05/16 07:32
#include <iostream>#include <cstdio>#include <string.h>using namespace std;const int MAXN = 100 + 10;int n, k;int c[MAXN][MAXN];int ans[MAXN];int match[MAXN];bool vis[MAXN];int cur;bool dfs(int u){    for (int i = 1; i <= n; i++)    {        if (!vis[i] && c[u][i] == cur)        {            vis[i] = true;            if (match[i] == -1 || dfs(match[i]))            {                match[i] = u;                return true;            }        }    }    return false;}void solve(){    int tot = 0;    for (int i = 1; i <= 50; i++)    {        memset(match, -1, sizeof(match));        int num = 0;        cur = i;        for (int j = 1; j <= n; j++)        {            memset(vis, false, sizeof(vis));            if (dfs(j))            {                num++;            }        }        if (num > k)        {            ans[tot++] = i;        }    }    if (tot == 0)    {        cout << -1;    }    for (int i = 0; i < tot; i++)    {        cout << ans[i];        if (i != tot - 1)        {            cout << ' ';        }    }    cout << endl;}void input(){    int x;    while (cin >> n >> k)    {        if (!n && !k)        {            break;        }        memset(c, 0, sizeof(c));        for (int i = 1; i <= n; i++)        {            for (int j = 1; j <= n; j++)            {                scanf("%d", &x);                c[i][j] = x;            }        }        solve();    }}int main(){    input();    return 0;}

0 0
原创粉丝点击