hdu1151 Air Raid
来源:互联网 发布:win7装mac os双系统 编辑:程序博客网 时间:2024/06/09 00:51
http://acm.hdu.edu.cn/showproblem.php?pid=1151
增广路的变种2:DAG图的最小路径覆盖=定点数-最大匹配数
1 #include<iostream> 2 #include<stdio.h> 3 #include<string.h> 4 #include<stdlib.h> 5 #include<math.h> 6 using namespace std; 7 const int N=510; 8 int a[N][N]; 9 int use[N];10 int match[N];11 int n;12 int dfs(int u)13 {14 for(int i=1;i<=n;i++)15 {16 if(a[u][i] && !use[i])//判断是否可匹配,以及是否使用17 {18 use[i]=1;//标记使用19 if(match[i]==-1 || dfs(match[i]))//未匹配,直接进行匹配20 { //已匹配,将原匹配进行拆分,去选择其他可匹配的选项21 match[i]=u; //再将当前进行强制匹配22 return 1;23 }24 }25 }26 return 0;27 }28 int bipartite()29 {30 int res=0;31 memset(match,-1,sizeof(match));32 for(int i=1;i<=n;i++)33 {34 memset(use,0,sizeof(use));35 if(dfs(i))36 res++;37 }38 return res;39 }40 int main()41 {42 //freopen("in.txt","r",stdin);43 int t;44 scanf("%d",&t);45 while(t--)46 {47 scanf("%d",&n);48 memset(a,0,sizeof(a));49 int m,q,p;50 scanf("%d",&m);51 for(int i=0;i<m;i++)52 {53 scanf("%d%d",&q,&p);54 a[q][p]=1;55 }56 int x=n-bipartite();57 printf("%d\n",x);58 }59 return 0;60 }
阅读全文
0 0
- Hdu1151 Air Raid
- HDU1151:Air Raid
- HDU1151 Air Raid
- hdu1151 Air Raid
- hdu1151——Air Raid
- ZOJ1525&&POJ1422&&HDU1151-Air Raid
- hdu1151 Air Raid (最小路径覆盖)
- hdu1151 Air Raid --- 最小路径覆盖
- hdu1151 air Raid(最小路径覆盖)
- hdu1151 Air Raid(最小边覆盖)
- Hdu1151 Air Raid(最小覆盖路径)
- Air Raid POJ1422 & HDU1151 最小路径覆盖
- hdu1151 Air Raid 最小路径覆盖
- 【图算法之二分图】HDU1151---Air Raid
- hdu1151 Air Raid,DAG图的最小路径覆盖
- hdu1151——Air Raid(最小路径覆盖)
- HDU1151 Air Raid (DAG图的最小覆盖)
- 【hdu1151】—Air Raid(最小路径覆盖)
- hdu1102
- 2015-05-26 随笔
- 万变不离其宗之海量数据下的算法问题处理思路
- hdu2063 过山车
- hdu1150 Machine Schedule
- hdu1151 Air Raid
- Springboot 整合 Mybatis 的完整 Web 案例
- hdu1068 Girls and Boys
- 奇奇怪怪技术贴之KindleForPC
- RPC , netty ,webSocket基于长链接的描述
- VS2013 error 集
- hdu2544 最短路
- Java基础:探秘Java中的String、StringBuilder以及StringBuffer
- hdu1874 畅通工程续