版权声明:来自: 码代码的猿猿的AC之路 http://blog.csdn.net/ck_boss https://blog.csdn.net/u012797220/article/details/32732003

最小点覆盖=最大匹配

Machine Schedule

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5350    Accepted Submission(s): 2650

Problem Description
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.

For k jobs given, each of them can be processed in either one of the two machines in particular mode. For example, job 0 can either be processed in machine A at mode_3 or in machine B at mode_4, job 1 can either be processed in machine A at mode_2 or in machine
B at mode_4, and so on. Thus, for job i, the constraint can be represent as a triple (i, x, y), which means it can be processed either in machine A at mode_x, or in machine B at mode_y.

Obviously, to accomplish all the jobs, we need to change the machine's working mode from time to time, but unfortunately, the machine's working mode can only be changed by restarting it manually. By changing the sequence of the jobs and assigning each job to
a suitable machine, please write a program to minimize the times of restarting machines. 

 

Input
The input file for this program consists of several configurations. The first line of one configuration contains three positive integers: n, m (n, m < 100) and k (k < 1000). The following k lines give the constrains of the k jobs, each line is a triple: i,
x, y.

The input will be terminated by a line containing a single zero.

 

Output
The output should be one integer per line, which means the minimal times of restarting machine.
 

Sample Input

5 5 10
0 1 1
1 1 2
2 1 3
3 1 4
4 2 1
5 2 2
6 2 3
7 2 4
8 3 3
9 4 3
0
 

Sample Output

3
 

Source
 
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm> using namespace std; const int maxn=1200; int n,m,p,linker[maxn];
bool mp[maxn][maxn],used[maxn]; bool dfs(int u)
{
for(int i=0;i<m;i++)
{
if(mp[u][i]&&!used[i])
{
used[i]=true;
if(linker[i]==-1||dfs(linker[i]))
{
linker[i]=u;
return true;
}
}
}
return false;
} int hungary()
{
int ret=0;
memset(linker,-1,sizeof(linker));
for(int i=0;i<n;i++)
{
memset(used,false,sizeof(used));
if(dfs(i)) ret++;
}
return ret;
} int main()
{
while(scanf("%d",&n)!=EOF&&n)
{
scanf("%d%d",&m,&p);
memset(mp,false,sizeof(mp));
for(int i=0;i<p;i++)
{
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
if(b&&c) mp[b][c]=true;
}
printf("%d\n",hungary());
}
return 0;
}

HDOJ 1150 Machine Schedule的更多相关文章

  1. hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  2. hdu 1150 Machine Schedule(最小顶点覆盖)

    pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  3. hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...

  4. 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)

    二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...

  5. hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  6. hdu 1150 Machine Schedule 最少点覆盖

    Machine Schedule Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...

  7. hdu 1150 Machine Schedule (二分匹配)

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  8. HDU——1150 Machine Schedule

    Machine Schedule Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) ...

  9. 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule

    二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...

随机推荐

  1. MySQL---时区问题

    1.控制台输入select now();  发现与北京时间相差8小时: 2.解决: 2.1.进入MySQL客户端  mysql -uroot -p 2.2.全局,当前会话时区设置set GLOBAL ...

  2. IDEA maven 配置,运行比较慢,加截本地仓库资源数据

    在 Runner 配置了参数: -DarchetypeCatalog=internal

  3. Linux内核设计与实现 总结笔记(第十四章)块I/O层

    一.剖析一个块设备 块设备最小的可寻址单元是扇区. 扇区大小一般是2的整数倍,最常见的是512字节. 因为各种软件的用途不同,所以他们都会用到自己的最小逻辑可寻址单元----块.块只能基于文件系统,是 ...

  4. 【WINDOWS】设置路由表实现有线内网,无线外网

    前提!!! 需要有线无线双网卡

  5. A Network in a Laptop: Rapid Prototyping for Software-Defined Networks

    文章名称:A Network in a Laptop: Rapid Prototyping for  Software-Defined Networks 文章来源:Lantz B , Heller B ...

  6. IO重定向与管道

    一.三种IO设备 程序:数据+指令 或 数据结构+算法 程序必须能够读入输入然后经过加工来产生结果,其接受的输入可以是变量.数组.列表.文件等等,生产出来的结果可以使变量.数组.列表.文件等等.即: ...

  7. os.environ.get()的用法

    os.environ.get()是python中os模块获取环境变量的一个方法 import os JS_ADDRESS = os.environ.get("PALM_JS_ADDRESS& ...

  8. linux添加新硬盘不需要重启识盘,及查看uuid

     添加新物理硬盘 用ssh工具连接到服务器,执行:fdisk -l 查看磁盘,并没有新加的硬盘 fdisk -l查看硬盘及分区状态     查看主机总线号,命令:ls /sys/class/scsi_ ...

  9. ajax传递json参数

    var pros = []; for(var i = 1; i <= 2; i++) { var obj = {}; obj.id = i; obj.age = i*20; pros = pro ...

  10. easyui表格适应bootstrap

    .panel1 { overflow: hidden; text-align: left; margin:; border:; -moz-border-radius: 0 0 0 0; -webkit ...