K - Treasure Exploration - POJ 2594(最小路径覆盖+闭包传递)
题意:给一个有向无环图,求出来最小路径覆盖,注意一个点可能会被多条路径重复
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; const int MAXN = ;
const int oo = 1e9+; bool G[MAXN][MAXN], used[MAXN];
int My[MAXN], N, M; void Floyd()
{
for(int k=; k<=N; k++)
for(int i=; i<=N; i++)
for(int j=; j<=N; j++)
{
if( G[i][k] && G[k][j] )
G[i][j] = true;
}
}
bool Find(int i)
{
for(int j=; j<=N; j++)
{
if( G[i][j] && used[j] == false )
{
used[j] = true;
if( !My[j] || Find( My[j] ) )
{
My[j] = i;
return true;
}
}
} return false;
} int main()
{
while(scanf("%d%d", &N, &M), N+M)
{
int i, u, v, ans=; memset(G, false, sizeof(G));
memset(My, false, sizeof(My)); while(M--)
{
scanf("%d%d", &u, &v);
G[u][v] = true;
} Floyd(); for(i=; i<=N; i++)
{
memset(used, false, sizeof(used));
if( Find(i) == true )
ans++;
} printf("%d\n", N-ans);
} return ;
}
K - Treasure Exploration - POJ 2594(最小路径覆盖+闭包传递)的更多相关文章
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total ...
- POJ 2594 Treasure Exploration (可相交最小路径覆盖)
题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ...
- POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 9794 Accepted: 3 ...
- POJ-2594 Treasure Exploration,floyd+最小路径覆盖!
Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...
- POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 8130 Accepted: 3 ...
- Treasure Exploration POJ - 2594 【有向图路径可相交的最小路径覆盖】模板题
Have you ever read any book about treasure exploration? Have you ever see any film about treasure ex ...
- POJ 2594 Treasure Exploration 最小可相交路径覆盖
最小路径覆盖 DAG的最小可相交路径覆盖: 算法:先用floyd求出原图的传递闭包,即如果a到b有路径,那么就加边a->b.然后就转化成了最小不相交路径覆盖问题. 这里解释一下floyd的作用如 ...
- POJ 3216 最小路径覆盖+floyd
Repairing Company Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 6646 Accepted: 178 ...
- poj 3216 (最小路径覆盖)
题意:有n个地方,m个任务,每个任务给出地点,开始的时间和完成需要的时间,问最少派多少工人去可以完成所有的任务.给出任意两点直接到达需要的时间,-1代表不能到达. 思路:很明显的最小路径覆盖问题,刚开 ...
随机推荐
- 关于 yii 验证码显示, 但点击不能刷新的处理
先说说 render 与 renderPartial, 各位看官, 先别走, 我没跑题, 这个问题如果需要解决, 关键就在 render 与 renderPartial 的区别. renderPart ...
- angular.bind
angular.bind :Returns a function which calls function fn bound to self (self becomes the this for fn ...
- 【转】mysql数据库中实现内连接、左连接、右连接
[转]mysql数据库中实现内连接.左连接.右连接 内连接:把两个表中数据对应的数据查出来 外连接:以某个表为基础把对应数据查出来 首先创建数据库中的表,数据库代码如下: /* Navicat MyS ...
- 各浏览器对 onbeforeunload 事件的支持与触发条件实现有差异
转载:http://www.w3help.org/zh-cn/causes/BX2047 标准参考 无. 问题描述 一般情况下,onbeforeunload 事件处理函数内会写入一些提示性语句,当用户 ...
- Apache下Worker模式MPM参数分析
我的worker.c配置如下:<IfModule mpm_worker_module> ServerLimit 32 ThreadLimit 128 StartServers ...
- 认识html文件基本结构
html文件的结构:一个HTML文件是有自己固定的结构的. <html> <head>...</head> <body>...</body> ...
- ASP.NET MVC with Entity Framework and CSS一书翻译系列文章之第三章:搜索、高级过滤和视图模型
在这一章中,我们首先添加一个搜索产品的模块以增强站点的功能,然后使用视图模型而不是ViewBag向视图传递复杂数据. 注意:如果你想按照本章的代码编写示例,你必须完成第二章或者直接从www.apres ...
- javascript之attribute 和 property
首先看看这两个单词的英文释义(来自有道词典).先是property: property ['prɔpəti] n. 性质,性能:财产:所有权 英英释义: any area set aside for ...
- html5 input属性
今天才接确html5 +css3 实在是太赞了. 下面我就来介绍一下今天我用到的 input 属性. html5 代码如下: <input type="text" plac ...
- python3数据类型--数字
数字 Python数字数据类型用于存储数值.数字数据类型是不允许改变的,所以如果改变数字数据类型的值,将重新分配内存空间. 以下实例在变量赋值时Number对象被创建: #!/usr/bin/env ...