题目来源:http://poj.org/problem?id=2594

参考博客:http://www.cnblogs.com/ka200812/archive/2011/07/31/2122641.html

题解:

最小路径覆盖=|P|-最大匹配数

单向图且没有循环,不可能存在a到b,b又到a,并且可以经过已经经过的点,所以对整个图进行处理,间接连接的点可以看作是直接连接

将整个图分成两边,点与点二分匹配,与平时的两种不同物体匹配不同

#include <iostream>
#include <cstring>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int maxn=500+5;
int ma[maxn][maxn],match[maxn];
bool used[maxn];
int n;
void floyed(){
for(int k=1;k<=n;k++)
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
if(ma[i][k]+ma[k][j]==2)ma[i][j]=1;
}
bool dfs(int x){
for(int i=1;i<=n;i++){
if(ma[x][i]&&used[i]==0){
used[i]=1;
if(match[i]==0||dfs(match[i])){
match[i]=x;
return 1;
} }
}
return 0;
}
int solve(){
memset(match,0,sizeof(match));
int ans=0;
for(int i=1;i<=n;i++){
memset(used,0,sizeof(used));
if(dfs(i))ans++;
}
return n-ans;
}
int main()
{
int m;
while(scanf("%d %d",&n,&m)==2){
if(n==0&&m==0)break;
memset(ma,0,sizeof(ma));
for(int i=1;i<=m;i++){
int a,b;
scanf("%d %d",&a,&b);
ma[a][b]=1;
}
floyed();
cout<<solve()<<endl;
}
return 0;
}

  

poj2594 机器人寻找宝藏(最小路径覆盖)的更多相关文章

  1. POJ2594 Treasure Exploration(最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8550   Accepted: 3 ...

  2. [POJ2594] Treasure Exploration(最小路径覆盖-传递闭包 + 匈牙利算法)

    传送门 引子: 有一个问题,是对于一个图上的所有点,用不相交的路径把他们覆盖,使得每个点有且仅属于一条路径,且这个路径数量尽量小. 对于这个问题可以把直接有边相连的两点 x —> y,建一个二分 ...

  3. poj2594 (最小路径覆盖 + floyd)

    题目链接  http://poj.org/problem?id=2594) 题目大意: 一个有向图中, 有若干条连接的路线, 问最少放多少个机器人,可以将整个图上的点都走过. 最小路径覆盖问题. 分析 ...

  4. POJ2594:Treasure Exploration(Floyd + 最小路径覆盖)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 9794   Accepted: 3 ...

  5. POJ-2594 Treasure Exploration,floyd+最小路径覆盖!

                                                 Treasure Exploration 复见此题,时隔久远,已忘,悲矣! 题意:用最少的机器人沿单向边走完( ...

  6. POJ2594 Treasure Exploratio —— 最小路径覆盖 + 传递闭包

    题目链接:https://vjudge.net/problem/POJ-2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 655 ...

  7. POJ-2594 Treasure Exploration floyd传递闭包+最小路径覆盖,nice!

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8130   Accepted: 3 ...

  8. POJ2594 Treasure Exploration【DAG有向图可相交的最小路径覆盖】

    题目链接:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K T ...

  9. poj2594——最小路径覆盖

    Description Have you ever read any book about treasure exploration? Have you ever see any film about ...

随机推荐

  1. java反射笔记

    反射(reflect) 1. Class对象 1.1 什么是Class对象 当JVM加载某个class文件的时候,会自动创建一个唯一的Class对象(注意:由同一个类加载器加载的class文件),这个 ...

  2. e lisp 常用缓冲区函数详解

    e lisp 常用缓冲区函数详解 函数名 函数概要 buffer-name 返回当前缓冲区的名字 buffer-file-name 返回当前缓冲区所指文件的名字,包括路径 current-buffer ...

  3. 线程--实现Runnable接口

    实现Runnable接口,创建线程步骤: 1.定义类,并实现Runnable接口 2.重写Runnable接口中的run()方法 3.通过Thread类建立线程对象 4.将实现了Runnable接口的 ...

  4. 详解 JSONP跨域请求的实现

          跨域问题是由于浏览器为了防止CSRF攻击(Cross-site request forgery跨站请求伪造),避免恶意攻击而带来的风险而采取的同源策略限制.当一个页面中使用XMLHTTPR ...

  5. 16.Python网络爬虫之Scrapy框架(CrawlSpider)

    引入 提问:如果想要通过爬虫程序去爬取”糗百“全站数据新闻数据的话,有几种实现方法? 方法一:基于Scrapy框架中的Spider的递归爬取进行实现(Request模块递归回调parse方法). 方法 ...

  6. CSS 浮动(float)与定位(position)

    一.浮动 1.三个属性:left.right.none. 2.特点:容易造成父项塌陷,故在父项需要清除浮动 3.父项塌陷现象 4.父项塌陷解决方案(建议使用):清除浮动 .parent:after{ ...

  7. P2690 接苹果 (DP)

    补一下dp的思路: dp[i][j]表示第 i 分钟转 j  次所得到的最大值.很容易得到这个dp的推导式. 图中¢()函数表示成立为1, 不成立为0的函数. #include<cmath> ...

  8. 一步一步和我学Apache JMeter

    一. Apache JMeter介绍 1. Apache JMeter是什么? Apache JMeter 是Apache组织的开放源代码项目,是一个100%纯Java桌面应用,用于压力测试和性能测量 ...

  9. Spring Security(二十七):Part II. Architecture and Implementation

    Once you are familiar with setting up and running some namespace-configuration based applications, y ...

  10. ajax如何增加请求头

    代码如下(主要关键就是headers,大家可以根据需要来增加请求头): $.ajax({ type: "POST", timeout: , // 超时时间 10 秒 headers ...