HDU 3279 二分图最大匹配

DES: 就是说对每个人都给你一个区间。但一个人只匹配一个数。问你满足匹配的人的序号字典序最大时的最大匹配是什么。

前几天刚做的UVALive 6322...当然是不一样的...那个要求的最大匹配的个数...求V2的最小字典序...这个呢...就是最大匹配中V1字典序最小是多少...(已晕菜)

大概理解了算法工作流程...对每一个V1中的位置...寻找匹配...直到找不到增广路算法结束...先匹配谁就可以先满足它的匹配咯...(是吗...)

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

int n;
int g[70][100010];
int vis[100010];
int link[100010];
int m;
int minn, maxx;

int dfs(int x)
{
    for (int y=minn; y<=maxx; ++y)
    {
        if (!vis[y] && g[x][y])
        {
            vis[y] = 1;
            if (link[y] == 0 || dfs(link[y]))
            {
                link[y] = x;
                return 1;
            }
        }
    }
    return 0;
}

void search()
{
    for (int x=n; x>=1; --x)
    {
        memset(vis, 0, sizeof(vis));
        if (dfs(x)) m++;
    }
}

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        cin >> n;
        m = 0;
        memset(g, 0, sizeof(g));
        memset(vis, 0, sizeof(vis));
        memset(link, 0, sizeof(link));
        minn = 100010, maxx = -1;

        for (int i=1; i<=n; ++i)
        {
            int x, y;
            cin >> x >> y;
            if (minn > x) minn = x;
            if (maxx < y) maxx = y;
            for (int j=x; j<=y; ++j)
            {
                g[i][j] = 1;
            }
        }
         search();
         cout << m << endl;
         int ans[70];
         memset(ans, 0, sizeof(ans));
         int cnt = 0;

         for (int x=minn; x<=maxx; ++x)
         {
             if (link[x] != 0)
             {
                ans[cnt++] = link[x];
             }
         }
         sort(ans, ans+cnt);
         for (int i=0; i<cnt; ++i)
         {
             if (i != 0) cout << ' ';
             cout << ans[i];
         }
         cout << endl;
    }
    return 0;
}
LOoK
原文地址:https://www.cnblogs.com/icode-girl/p/4703817.html