BZOJ1191: [HNOI2006]超级英雄Hero

【传送门:BZOJ1191


简要题意:

给出m个问题,给出n个锦囊,每个问题可以用两种锦囊解决(有可能这两种锦囊是同一种,这就很尴尬,可能出数据的神犇有点儿懒),但每种锦囊只能用一次,而且只有解决了前面的问题才能解决后面的问题,求出最多能解决多少问题


题解:

就是很裸的二分图匹配啦,直接匈牙利。


参考代码:

#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
struct node
{
    int x,y,next;
}a[2100];int len,last[2100];
int match[2100];
void ins(int x,int y)
{
    len++;
    a[len].x=x;a[len].y=y;
    a[len].next=last[x];last[x]=len;
}
bool chw[2100];
bool findmuniu(int x)
{
    for(int k=last[x];k;k=a[k].next)
    {
        int y=a[k].y;
        if(chw[y]==true)
        {
            chw[y]=false;
            if(match[y]==0||findmuniu(match[y])==true)
            {
                match[y]=x;
                return true;
            }
        }
    }
    return false;
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    memset(match,0,sizeof(match));
    len=0;memset(last,0,sizeof(last));
    for(int i=1;i<=m;i++)
    {
        int y1,y2;
        scanf("%d%d",&y1,&y2);
        y1++;y2++;
        if(y1==y2) ins(i,y1+m);
        else
        {
            ins(i,y1+m);
            ins(i,y2+m);
        }
    }
    int ans=0;
    for(int i=1;i<=m;i++)
    {
        memset(chw,true,sizeof(chw));
        if(findmuniu(i)==true) ans++;
        else break;
    }
    printf("%d\n",ans);
    return 0;
}

转载于:https://www.cnblogs.com/Never-mind/p/7526044.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值