hdu 1151 Air Raid 【DAG最小路径覆盖】
来源:互联网 发布:免费网络直播加速器 编辑:程序博客网 时间:2024/05/18 03:17
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1151
DAG最小路径覆盖 = 结点数 - 最大匹配数
代码:
#include <iostream> #include <algorithm> #include <set> #include <map> #include <string.h> #include <queue> #include <sstream> #include <stdio.h> #include <math.h> #include <stdlib.h> using namespace std;int n, m;int p[1000][1000];int book[1000];int match[1000];int dfs(int u){ for (int i = 1; i <= n; i++) { if (book[i] == 0 && p[u][i] == 1) { book[i] = 1; if (match[i] == 0 || dfs(match[i])) { match[i] = u; return 1; } } } return 0;}int main(){ int t; scanf("%d",&t); while (t--) { scanf("%d %d", &n, &m); memset(match, 0, sizeof(match)); memset(p, 0, sizeof(p)); int u, v; while(m--) { scanf("%d %d", &u, &v); p[u][v] = 1; } int ans = 0; for (int i = 1; i <= n; i++) { memset(book, 0, sizeof(book)); if (dfs(i)) ans++; } printf("%d\n", n - ans); } return 0;}
0 0
- hdu 1151 Air Raid DaG 图的最小路径覆盖
- hdu 1151 Air Raid(DAG最小路径覆盖)
- hdu 1151 Air Raid 【DAG最小路径覆盖】
- hdu 1151 Air Raid DAG最小路径覆盖
- HDU 1151 Air Raid(DAG上的最小路径覆盖)
- POJ1422 Air Raid 【DAG最小路径覆盖】
- Air Raid 【DAG 最小路径覆盖】
- hdu 1151 Air Raid最小路径覆盖
- hdu 1151 Air Raid (最小路径覆盖)
- HDU 1151 Air Raid( 最小路径覆盖 )
- hdu 1151 Air Raid ( 最小路径覆盖 )
- Air Raid hdu 1151 最小路径覆盖
- [hdu 1151] Air Raid(最小路径覆盖)
- HDU 1151 Air Raid 最小路径覆盖
- HDU 1151 Air Raid【最小路径覆盖】
- HDU 1151 Air Raid (最小路径覆盖)
- HDU 1151 Air Raid( 最小路径覆盖)
- [HDU 1151] Air Raid 最小路径覆盖
- C语言的整型溢出问题
- 设置 SeekBar宽度全屏
- LBP简介
- 【Block回调】用于参数传递很不错的例子。
- 易改1Checker 英文写作软件
- hdu 1151 Air Raid 【DAG最小路径覆盖】
- Asp.Net 小型网站的制作(二),涵盖了asp.net里面所有的基础知识
- g++: command not found的解决
- Ubuntu中定时
- 盘点一些唯美复古惊艳的古风句子
- 设置Intel 82579LM 抓Vlan tag报文
- UIday1301:block复习
- Android Animation动画(很详细)
- POJ - 1679 The Unique MST(最小生成树是否唯一)