hdu1150 Machine Schedule 最小点覆盖

As we all know, machine scheduling is a very classical problem in computer science and has been studied for a very long history. Scheduling problems differ widely in the nature of the constraints that must be satisfied and the type of schedule desired. Here we consider a 2-machine scheduling problem.

There are two machines A and B. Machine A has n kinds of working modes, which is called mode_0, mode_1, …, mode_n-1, likewise machine B has m kinds of working modes, mode_0, mode_1, … , mode_m-1. At the beginning they are both work at mode_0.

题解:有两个机器A,B和N个要执行的任务。每个机器有M中不同的模式,每个任务恰好在一个机器上执行。如果在A机器上执行,A机器模式应为Ai,在B机器上执行,则B机器的模式为Bi,任务顺序任意,但是每次切换模式机器要关一次机,安排合理的方案使得机器重启次数最少。

题意转了半天。。这是个最小点覆盖的问题。当然知道了这是什么问题那么解起来就方便了。

二分图最小点覆盖=最大匹配数。

#include<cstdlib>
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define LL long long
#define maxn 1001
#define INF 2147483646
using namespace std;
int vit[maxn];
int map[maxn][maxn];
int link[maxn];
int n,m,k;
bool dfs(int u)
{
    for(int i=0;i<m;i++)
    {
        if(!vit[i]&&map[u][i])
        {
            vit[i]=1;
            if(link[i]==-1||dfs(link[i]))//反向找出增广路(交错树)
            {
                link[i]=u;
                return true;
            }
        }
    }
    return false;
}
void solve(int &ans)
{
    for(int i=0;i<n;i++)
    {
        memset(vit,0,sizeof(vit));
        if(dfs(i))
            ans++;
    }
}
int main()
{
    while(cin>>n,n)
    {
        int ans=0;
        cin>>m>>k;
        memset(map,0,sizeof(map));
        memset(link,-1,sizeof(link));
        for(int i=0;i<k;i++)
        {
            int t,x,y;
            cin>>t>>x>>y;
            if(x>0&&y>0)
            map[x][y]=1;
        }
        solve(ans);
        cout<<ans<<endl;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值