poj 1325 二分图最小点覆盖(机器模式的选择)
来源:互联网 发布:刘备是汉室宗亲吗 知乎 编辑:程序博客网 时间:2024/05/01 10:06
题意:机器A有n(0~n-1)个模式,机器B有m(0~m-1)个模式。有k个任务,可以用机器A的i模式做或用机器B的j模式做。任务无先后,换模式需重启机器,开始时两个机器都在模式0,且已经开机。问最少需要开机多少次。
思路:求最小点覆盖。最小点覆盖=最大匹配。故为hungary模板。注意可以用两个机器模式0做的就不必考虑了。
#include <stdio.h>#include <string.h>#define N 105#define M 1005int map[N][N];int visited[N],link[N];int n,m,k;int dfs(int i){int j;for(j = 0;j<m;j++)if(!visited[j] && map[i][j]){visited[j] = 1;if(link[j]==-1 || dfs(link[j])){link[j] = i;return 1;}}return 0;}int hungary(){int i,res=0;for(i = 0;i<n;i++){memset(visited,0,sizeof(visited));if(dfs(i))res++;}return res;}int main(){freopen("a.txt","r",stdin);while(scanf("%d",&n)&&n){int i,a,b;memset(map,0,sizeof(map));memset(link,-1,sizeof(link));scanf("%d %d",&m,&k);while(k--){scanf("%d %d %d",&i,&a,&b);if(a&&b)map[a][b] = 1;}printf("%d\n",hungary());}return 0;}
0 0
- poj 1325 二分图最小点覆盖(机器模式的选择)
- POJ 1325二分图,最小点覆盖
- poj 1325 Machine Schedule(二分图的最小点覆盖)
- POJ 2226 二分图 最小点覆盖
- poj 2226 二分图最小点覆盖
- POJ 1325 二分图最小点集覆盖
- POJ 1325 Machine Schedule 二分图最小点覆盖
- POJ 1325 Machine Schedule 二分图 最小点覆盖
- POJ - 1325 Machine Schedule 二分图 最小点覆盖
- POJ 1325 Machine Schedule(二分匹配 最小点覆盖)
- poj 1325 二分图最小顶点覆盖(机器重启)
- POJ 1325Machine Schedule(二分图最大匹配最小点覆盖)
- POJ 1325-Machine Schedule(二分图_最大匹配最小点覆盖)
- POJ 1325 Machine Schedule (最小点覆盖 && 二分图最大匹配)
- POJ-1325-Machine Schedule-最小点覆盖(二分图-匈牙利算法)
- poj3041 二分图的最小点覆盖
- 二分图的最小点覆盖
- poj1325 二分图的最小点覆盖
- Winform 移植到 WPF 中 窗体变丑 解决方案
- 《深度学习C++对象模型》学习笔记2:构造函数语意学
- 使用 Timer 进行任务调度
- alsa_aplay 出现 Warning: rate is not accurate
- A mid-summer night’s dream uva+二分/中位数
- poj 1325 二分图最小点覆盖(机器模式的选择)
- sizeof对字符数组字符串使用
- eclipse最新dropins安装插件
- linux驱动开发学习路线
- velocity 单引号和双引号转义
- poj 1042 贪心
- Singleton 单例模式
- poj 3281 最大流(牛吃喝的最大数量)
- 深度搜索C++对象模型1-关于对象