题目大意:有两个机器,A机器有n种工作模式,B机器有m种工作模式,刚開始两个机器都是0模式。假设要切换模式的话,机器就必须的重新启动

有k个任务,每一个任务都能够交给A机器的i模式或者B机器的j模式完毕,问要重新启动多少次机器才干完毕任务

解题思路:两个机器的点分为两个点集。点集之间的关系就是任务了。要将全部任务都完毕。就要将全部边都覆盖掉,所以就是求最小点覆盖了。

这里有一个点要注意。假设全部任务中都有一个0,那么机器就不用重新启动了,重新启动次数就为0了(由于刚開始都是0)

#include<cstdio>
#include<vector>
#include<cstring>
using namespace std;
const int N = 110;
int n, m, k;
int vis[N], link[N];
bool flag;
vector<int> g[N]; void init() { for(int i = 1; i < n; i++)
g[i].clear(); int x, y, z;
for(int i = 0; i < k; i++) {
scanf("%d%d%d", &x, &y, &z);
if(y * z == 0)
continue;
g[y].push_back(z);
}
memset(link, -1, sizeof(link));
} bool dfs(int u) {
for(int i = 0; i < g[u].size(); i++) {
int v = g[u][i];
if(vis[v])
continue;
vis[v] = 1;
if(link[v] == -1 || dfs(link[v])) {
link[v] = u;
return true;
}
}
return false;
} void hungary() {
int ans = 0;
for(int i = 1; i < n; i++) {
memset(vis, 0, sizeof(vis));
if(dfs(i))
ans++;
}
printf("%d\n",ans);
} int main() {
while(scanf("%d", &n) != EOF && n) {
scanf("%d%d", &m, &k);
init();
hungary();
}
return 0;
}

POJ - 1325 Machine Schedule 二分图 最小点覆盖的更多相关文章

  1. POJ 1325 Machine Schedule(最小点覆盖)

    http://poj.org/problem?id=1325 题意: 两种机器A和B.机器A具有n种工作模式,称为mode_0,mode_1,...,mode_n-1,同样机器B有m种工作模式mode ...

  2. UVA1194 Machine Schedule[二分图最小点覆盖]

    题意翻译 有两台机器 A,B 分别有 n,m 种模式. 现在有 k 个任务.对于每个任务 i ,给定两个整数$ a_i\(和\) b_i$,表示如果该任务在 A上执行,需要设置模式为 \(a_i\): ...

  3. [poj1325] Machine Schedule (二分图最小点覆盖)

    传送门 Description As we all know, machine scheduling is a very classical problem in computer science a ...

  4. HDU 1150 Machine Schedule (二分图最小点覆盖)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1150 有两个机器a和b,分别有n个模式和m个模式.下面有k个任务,每个任务需要a的一个模式或者b的一个 ...

  5. POJ 1325 Machine schedine (二分图-最小点覆盖数=最大匹配边数)

    As we all know, machine scheduling is a very classical problem in computer science and has been stud ...

  6. [POJ] 2226 Muddy Fields(二分图最小点覆盖)

    题目地址:http://poj.org/problem?id=2226 二分图的题目关键在于建图.因为“*”的地方只有两种木板覆盖方式:水平或竖直,所以运用这种方式进行二分.首先按行排列,算出每个&q ...

  7. poj 1325 Machine Schedule 最小点覆盖

    题目链接:http://poj.org/problem?id=1325 As we all know, machine scheduling is a very classical problem i ...

  8. HDU - 1150 POJ - 1325 Machine Schedule 匈牙利算法(最小点覆盖)

    Machine Schedule As we all know, machine scheduling is a very classical problem in computer science ...

  9. POJ 1325 Machine Schedule(zoj 1364) 最小覆盖数

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=364 http://poj.org/problem?id=1325 题目大意: ...

随机推荐

  1. leetcode659. Split Array into Consecutive Subsequences

    leetcode659. Split Array into Consecutive Subsequences 题意: 您将获得按升序排列的整数数组(可能包含重复项),您需要将它们拆分成多个子序列,其中 ...

  2. MYSQL分段统计

    产品表 CREATE TABLE `product` ( `product_id` int(11) NOT NULL AUTO_INCREMENT, `product_model` varchar(2 ...

  3. PPT文化

    PPT文化,yes or no? 知识是有体系的,有的时候刚接触的时候可以 推导技术 ,汇报.吹牛都可以应用上,并且可以让别人想想. 但是实际应用技术,就需要涉及很多详细的技术细节,如果少掉一个看似极 ...

  4. iptables详解与Centos7 关闭防火墙

    http://www.cnblogs.com/metoy/p/4320813.html CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 1.直接关闭防 ...

  5. .NET:CLR via C# User-Mode Constructs

    The CLR guarantees that reads and writes to variables of the following data types are atomic: Boolea ...

  6. Spring+Quartz实现文件中转站

    其实这个功能QQ邮箱就有,为什么还要自己开发一个呢?因为有的文件非常重要...其实是客户要求... 那么我们先来看一下QQ的界面: 我们设计的界面: 文件要到期了是否通知用户?这里我们支持邮件及短信方 ...

  7. select case when if 的一些用法

    概述:sql语句中的case语句与高级语言中的switch语句,是标准sql的语法,适用于一个条件判断有多种值的情况下分别执行不同的操作. 首先,让我们看一下CASE的语法.在一般的SELECT中,其 ...

  8. iOS:UIScrollView控件和UIPageControl控件的详解

    UIScrollView滚动视图控件和UIPageControl分页视图控件:    UIScrollView用于显示多于一个屏幕的内容,超出屏幕范围的内容可以通过滑动进行查看,当然UIPagecon ...

  9. Objective-C:异常的处理

    // // main.m // 03-动态绑定 // // Created by mac on 15/8/11. // Copyright (c) 2015年. All rights reserved ...

  10. struts 2中为什么抽象包不能包含action?

    struts 2中为什么抽象包不能包含action?麻烦写详细点!