Air Raid---hdu1151(最小路径覆盖)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1151
最小路径覆盖 == 顶点数 - 最大匹配。
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 130 int maps[N][N], vis[N], used[N], n, m, ans;
bool Find(int u)
{
for(int i=; i<=n; i++)
{
if(!vis[i] && maps[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} int main()
{
int T, x, y;
scanf("%d", &T);
while(T--)
{
memset(maps, , sizeof(maps));
memset(used, , sizeof(used));
scanf("%d%d", &n, &m);
while(m--)
{
scanf("%d%d", &x, &y);
maps[x][y] = ;
}
ans=;
for(int i=; i<=n; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n",n-ans);
}
return ;
}
Air Raid---hdu1151(最小路径覆盖)的更多相关文章
- hdu 1151 Air Raid(二分图最小路径覆盖)
http://acm.hdu.edu.cn/showproblem.php?pid=1151 Air Raid Time Limit: 1000MS Memory Limit: 10000K To ...
- HDU 1151 Air Raid(最小路径覆盖)
题目大意: 有n个城市,m条道路,城市的道路是单向. 现在我们的伞兵要降落在城市里,然后我门的伞兵要搜索所有道路.问我们最少占领多少个城市就可以搜索所有的道路了. 我们可以沿着道路向前走到达另一个城 ...
- HDU - 1151 Air Raid (最小路径覆盖)
题意:给定一个有向无环图,求最少划分几条路径,使之能够覆盖所有点. 分析:这可以转化为DAG上的最小路径覆盖问题. 路径覆盖的定义:有向图中,路径覆盖就是在图中找一些路径,使之覆盖了图中的所有顶点,且 ...
- Air Raid(最小路径覆盖)
Description Consider a town where all the streets are one-way and each street leads from one interse ...
- HDU1151 Air Raid —— 最小路径覆盖
题目链接:https://vjudge.net/problem/HDU-1151 Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory L ...
- hdu1151 Air Raid,DAG图的最小路径覆盖
点击打开链接 有向无环图的最小路径覆盖 = 顶点数- 最大匹配 #include <queue> #include <cstdio> #include <cstring& ...
- 【网络流24题----03】Air Raid最小路径覆盖
Air Raid Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Su ...
- POJ1422 Air Raid 【DAG最小路径覆盖】
Air Raid Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6763 Accepted: 4034 Descript ...
- POJ 1422 Air Raid(二分图匹配最小路径覆盖)
POJ 1422 Air Raid 题目链接 题意:给定一个有向图,在这个图上的某些点上放伞兵,能够使伞兵能够走到图上全部的点.且每一个点仅仅被一个伞兵走一次.问至少放多少伞兵 思路:二分图的最小路径 ...
随机推荐
- 学习:erlang的不定长数据包头部。
- JS中document对象详解
转自:http://www.cnblogs.com/andycai/archive/2010/06/29/1767351.html 对象属性 document.title //设置文档标题等价于HTM ...
- C语言简单选择排序
#include <stdio.h> int main(int argc, char const *argv[]) { // 将数组按照从小到大排序 , , , , , }; int i, ...
- 各大门户网站全局CSS样式定义
1.网易 body { text-align: center; font-family:"宋体", arial;margin:0; padding:0; background: # ...
- js常用总结
常用总结,方便大家学习共享. 1.document.write(""); 输出语句 2.JS中的注释为// 3.传统的HTML文档顺序是:document->html-& ...
- string permutation with upcase and lowcase
Give a string, which only contains a-z. List all the permutation of upcase and lowcase. For example, ...
- Mybatis中insert
<insert id="insert" parameterType="Currency"> INSERT INTO YZ_SECURITIES_CU ...
- JavaScript中eval()函数
eval调用时,实例为eval( "( javascript代码 )" ), eval() 函数可将字符串转换为代码执行,并返回一个或多个值.
- Sass-学习笔记【进阶篇】
特别说明: 没有sass基础请移步:[Sass-学习笔记[基础篇]]http://www.cnblogs.com/padding1015/articles/7056323.html 最底部附结构图(实 ...
- LeetCode——Intersection of Two Linked Lists
Description: Write a program to find the node at which the intersection of two singly linked lists b ...