HDOJ 1150 Machine Schedule
版权声明:来自: 码代码的猿猿的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
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.
x, y.
The input will be terminated by a line containing a single zero.
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
#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的更多相关文章
- hdoj 1150 Machine Schedule【匈牙利算法+最小顶点覆盖】
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- hdu 1150 Machine Schedule(最小顶点覆盖)
pid=1150">Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- hdu 1150 Machine Schedule(二分匹配,简单匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 Machine Schedule Time Limit: 2000/1000 MS (Java/ ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- hdu 1150 Machine Schedule 最少点覆盖转化为最大匹配
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule 最少点覆盖
Machine Schedule Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- hdu 1150 Machine Schedule (二分匹配)
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU——1150 Machine Schedule
Machine Schedule Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 二分图最大匹配(匈牙利算法)简介& Example hdu 1150 Machine Schedule
二分图匹配(匈牙利算法) 1.一个二分图中的最大匹配数等于这个图中的最小点覆盖数 König定理是一个二分图中很重要的定理,它的意思是,一个二分图中的最大匹配数等于这个图中的最小点覆盖数.如果你还不知 ...
随机推荐
- 运行biggan demo
http://www.zhuanzhi.ai/document/8705953a704e1bf8e051c161d1587d88
- github-搜索功能
in:name spring boot stars:>3000 //在标题上查找spring boot 并且 stars >3000 in:readme spring boot sta ...
- div写表格,原生滚动条,数据能够自动滚动
如何让表格的滚动条能够自动滚动呢? html: <div class="tabinner5"> <div class="tab5 tab5a" ...
- SQL Server性能调优--优化建议(一)
序言 当数据量小的时候,SQL优化或许无关紧要,但是当数据量达到一定量级之后,性能优化将变得至关重要,甚至决定系统成败. 定位慢查询 查询编译以来cpu耗时总量最多的前50条 --查询编译以来 cpu ...
- window 下 Atom 侧边栏字体大小设置
在 File 处找到 Settings 点击 找到 Themes 点击 找到 your stylesheet 点击 在 .tree-view 处设置即可, (按照 css 样式来写即可保存生效).
- 最简单的flask项目详解
# 第一部分,初始化:所有的Flask都必须创建程序实例, # web服务器使用wsgi协议,把客户端所有的请求都转发给这个程序实例 # 程序实例是Flask的对象,一般情况下用如下方法实例化 # F ...
- 字节对齐#pragma pack
这是给编译器用的参数设置,有关结构体字节对齐方式设置, #pragma pack是指定数据在内存中的对齐方式. #pragma pack (n) 作用:C编译器将按照n个字节对 ...
- mui初级入门教程(六)— 模板页面实现原理及多端适配指南
文章来源:小青年原创发布时间:2016-07-26关键词:mui,webview,template,os,多端适配转载需标注本文原始地址: http://zhaomenghuan.github.io. ...
- ECharts插件介绍(图表库)
ECharts是一个非常好用的插件,用于进行 树状图,折线图,饼图,地图等等,系列视图的绘制.(详情看官网) 了解: AMD:模块化开发方式: 引入文件后:console.log(echarts) / ...
- Java基础数据类型小结
1. 记忆中的数据类型: 记忆中java一共有八种基础数据:boolean,byte,char,int,long,float,double,还有一种记不起来. 他们的长度分别为: 他们的用处 ...