这道题是让求派出机器人的最少数量,乍一看以为是简单的求最小路径覆盖,后来发现错了,因为有的点可以走多次,而二分中每个点只能走一次,所以要先用floyd进行传递闭包,然后用二分

#include<stdio.h>
#include<string.h>
#define N 505 int match[N],visit[N];
int n,m;
int g[N][N];
int DFS(int u)
{
int i;
for(i=;i<=n;i++) if(!visit[i]&&g[u][i])
{
visit[i]=;
if(match[i]==-||DFS(match[i]))
{
match[i]=u;
return ;
}
}
return ;
}
int maxMatch()
{
memset(match,-,sizeof(match));
int ans=,i;
for(i=;i<=n;i++)
{
memset(visit,,sizeof(visit));
if(DFS(i)) ans++;
}
return ans;
}
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]=;
}
int main()
{
int a,b;
while(scanf("%d%d",&n,&m))
{
memset(g,,sizeof(g));
if((n+m)==)
break;
for(int i=;i<m;i++)
{
scanf("%d%d",&a,&b);
g[a][b]=;
}
Floyd();
printf("%d\n",n-maxMatch());
}
return ;
}

poj2459 Treasure Exploration (闭包+二分)的更多相关文章

  1. poj 2594 Treasure Exploration (二分匹配)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6558   Accepted: 2 ...

  2. poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)

    http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total ...

  3. Treasure Exploration(二分最大匹配+floyd)

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

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

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

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

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

  6. POJ2594 Treasure Exploration

    Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 8193   Accepted: 3358 Description Have ...

  7. POJ 2594 Treasure Exploration(最小路径覆盖变形)

    POJ 2594 Treasure Exploration 题目链接 题意:有向无环图,求最少多少条路径能够覆盖整个图,点能够反复走 思路:和普通的最小路径覆盖不同的是,点能够反复走,那么事实上仅仅要 ...

  8. POJ Treasure Exploration 【DAG交叉最小路径覆盖】

    传送门:http://poj.org/problem?id=2594 Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K To ...

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

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

随机推荐

  1. 高性能浏览器网络(High Performance Browser Networking) 第二章

    第2章 TCP篇 互联网的核心是两个协议,IP和TCP. IP也叫Internet协议,提供主机到主机的路由和寻址:TCP,传输控制协议,在不可靠的传输通道上提供一个可靠的网络抽象.TCP / IP协 ...

  2. linux 内核源代码分析 - 获取数组的大小

    #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 測试程序: #include<stdio.h> #include<stdlib. ...

  3. (原) Jquery 判断设备是PC端,还是移动端

    判断设备是PC端,还是移动端 var ua = navigator.userAgent.toLocaleLowerCase(); var pf = navigator.platform.toLocal ...

  4. C# 8 函数 调用 常用类 时间 日期型

    函数:能够独立完成某个功能的模块. 好处:1.结构更清析(编写.维护方便 ).2.代码重用.3.分工开发. 四要素:名称,输入(参数),输出(返回的类型),加工(函数体) 语法: 返回类型 函数名(参 ...

  5. 搜索+剪枝——运筹帷幄 (road.cpp)

    运筹帷幄 (road.cpp) [题目描述] 刘邦军行至迷糊林,见其中瘴气围绕,又有青狼猛虎之兽,难于前行. 已知迷糊林是一个共有n个结点的图,点与点之间共有m条道路相连接,每条路有参数t,c,分别表 ...

  6. ubuntu 开启 rewrite 模块

    1.sudo a2enmod rewrite 开启Rewrite模块 (停用模块,使用 a2dismod) 2. 在/etc/apache2/ 修改apache2.conf 文件中把AllowOver ...

  7. Spring随笔 - 事务传播行为

    Spring定义了7种不同的事务传播行为: PROPAGATION_MANDATORY:表示该方法必须在事务中运行.如果当前事务不存在,则会抛出一个异常. PROPAGATION_NESTED:表示如 ...

  8. jQuery绑定事件-多种方式实现

    jQuery绑定事件-多种方式实现: <html> <head> <meta charset="utf-8" /> <script src ...

  9. 数组转DataTable

    using System; using System.Data; namespace ArrayToDataTable { class ArrayToDataTable { /// <summa ...

  10. 关于python命令在editor里编写与在interpreter里的编写的不同之处

    关于python命令在editor里编写与在interpreter里的编写的不同之处 其实用这个标题,我心里还是有点胆怯的.作为一个python入门的小白,不,编程入门的小白,我还不太确定我对edit ...