poj 1469 COURSES 【匈牙利匹配】
来源:互联网 发布:无线信道检测软件 编辑:程序博客网 时间:2024/05/22 16:39
题目链接:http://poj.org/problem?id=1469
题意:最大匹配学生与课程数。
解法:ans == 学生数量 YES else NO
代码:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace std;int n, m, num, k;int p[310][310];int book[310];int match[310];int t;bool vis[310];bool dfs(int u){ int i; for (i = 1; i <= m; i++) { if (book[i] == 0 && p[u][i] == 1) { book[i] = 1; if (match[i] == 0 || dfs(match[i])) { match[i] = u; return true; } } } return false;}int main(){ scanf("%d",&t); while (t--) { memset(p, 0, sizeof(p)); memset(match, 0, sizeof(match)); memset(vis,false,sizeof(vis)); scanf("%d%d",&n,&m); for (int i = 1; i <= n; i++) { scanf("%d",&num); for (int j = 1; j <= num; j++) { scanf("%d",&k); p[i][k] = 1; //p[num][m] = 1; } } int ans = 0; for (int i = 1; i <= n; i++) { memset(book, 0, sizeof(book)); if (dfs(i)) ans++; } if (ans == n) puts("YES"); else puts("NO"); } return 0;}
0 0
- poj 1469 COURSES 【匈牙利匹配】
- poj题目1469 COURSES (二分图匹配,匈牙利算法)
- POJ 1469 COURSES (二分图最大匹配 匈牙利算法)
- poj 1469 COURSES 二分图最大匹配 匈牙利算法
- POJ 1469 COURSES(匈牙利算法二分图最大匹配)
- POJ 1469-COURSES(二分图匹配入门-匈牙利算法)
- poj 1469 COURSES 匈牙利算法
- POJ 1469 COURSES【匈牙利算法入门 二分图的最大匹配 模板题】
- zoj 1140 poj 1469 COURSES(二分图匹配 匈牙利算法)
- POJ:1469 COURSES(匈牙利算法模版题)
- poj 匈牙利二分匹配算法2239 Selecting Courses
- POJ 2239 Selecting Courses(二分匹配匈牙利啊)
- poj 1469 COURSES (最大匹配)
- poj 1469 COURSES 【二分匹配】
- poj 1469 COURSES (二分匹配)
- pku 1469 COURSES(二分匹配,匈牙利算法)
- poj 1469 COURSES 二分图匹配初识
- poj 1469 COURSES 二分图匹配
- display的设定block;inline;inline-block
- AsyncDisplayKit -- ( facebook/新浪微博 ) 优化UI性能
- 记录
- Linux常用命令
- KD树在knn算法中的应用
- poj 1469 COURSES 【匈牙利匹配】
- HDU 4570 简单的DP
- Floyd-Warshall算法---求解任意两节点的最短路径
- 14级俱乐部成员
- hdu1100
- 安装CentOS7后修复windows开机启动项
- Linux值OSS的Mixer编程
- hibernate中的session介绍
- 程序猿必备