poj 2594 Treasure Exploration 可重复覆盖的二分图最小覆盖路径
来源:互联网 发布:nsga2算法讲解 编辑:程序博客网 时间:2024/05/22 01:47
题意:给出一个图,有N个点有宝藏,M条单向边,求用最少的机器人去挖宝藏。
思路:注意到You should notice that the roads of two different robots may contain some same point。说明有些点可以重复经过,所以只要考虑路径的两个端点即可,用floyd求传递闭包。
代码:
#include<stdio.h>#include<string.h>#include<algorithm>#include<math.h>#include<queue>#include<vector>#include<iostream>#define Maxn 500+10#define clr(a,b) memset(a,b,sizeof(a))using namespace std;int vis[Maxn],g[Maxn][Maxn],n,m,mat[Maxn],x,y;void floyd(){ for(int k=0;k<n;k++) for(int i=0;i<n;i++) for(int j=0;j<n;j++) if(g[i][k]&&g[k][j]) g[i][j]=1;}bool find(int x){ for(int i=0;i<n;i++) { if(!vis[i]&&g[x][i]) { vis[i]=1; if(mat[i]==-1||find(mat[i])) { mat[i]=x; return 1; } } } return 0;}int Hungary(int n){ int Max=0; clr(mat,-1); for(int i=0;i<n;i++) { clr(vis,0); if(find(i)) Max++; } return Max;}int main(){ while(~scanf("%d %d",&n,&m)) { if(n==0&&m==0) break; if(m==0) { printf("%d\n",n);continue;} clr(g,0); for(int i=0;i<m;i++) { scanf("%d %d",&x,&y); g[x-1][y-1]=1; } floyd(); printf("%d\n",n-Hungary(n)); } return 0;}
- poj 2594 Treasure Exploration 可重复覆盖的二分图最小覆盖路径
- POJ 2594--Treasure Exploration【二分图 && 最小路径覆盖 && 点可以重复走 && 传递闭包】
- POJ-2594-Treasure Exploration(可重点最小路径覆盖)
- Poj 2594 Treasure Exploration【可相交最小路径覆盖】
- POJ 2594 Treasure Exploration 最小路径覆盖
- POJ Treasure Exploration(DAG最小可相交路径覆盖)
- poj 2594 Treasure Exploration(可重点最小路径覆盖)(二分匹配+Floyd求传递闭包)
- 可重叠的最小路径覆盖 poj2594 Treasure Exploration
- POJ2594 Treasure Exploration【二分图最小路径覆盖】【Floyd】
- Treasure Exploration(POJ_2594) -有向图可重复点-最小路径覆盖
- POJ 2594 Treasure Exploration(传递闭包+最小路径覆盖)
- poj 2594 Treasure Exploration最小路径覆盖+传递闭包
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
- POJ 题目2594 Treasure Exploration(最小路径覆盖)
- poj 2594 Treasure Exploration 最小路径覆盖/最大匹配
- POJ 2594 — Treasure Exploration 最小路径覆盖
- POJ 2594 Treasure Exploration【最小路径覆盖+缩点】
- POJ 2594 Treasure Exploration(最小路径覆盖-hungary+Floyd)
- 转载 通过Java代码设置layout_weight
- 第七章 多态
- 随手记录一些学到得东西
- 【集合】LinkedList链表类
- 如何使用GoogleAnalytics统计特定页面(工作笔记3)
- poj 2594 Treasure Exploration 可重复覆盖的二分图最小覆盖路径
- Apophysis作品——潘多拉魔盒渲染日志
- 设计一个html布局器,能移动。拖拽,有属性框。并能生成页面
- 播放 wav 文件
- ArcGIS 10.1 for Server安装教程系列—— Linux下的单机安装
- winform拖拽自定义用户控件到设计器时报错, 而运行无错的情况
- Python对象的深复制与浅复制
- spring中使用mule的配置经验总结
- AppBar的WTL实现