http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19419   Accepted: 7642 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is…
题目链接: http://poj.org/problem?id=1469 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that sat…
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的课,如果可以做到每个学生代表不同的课程并且所有的课程都被代表输出"YES"(学生能代表一门课当且仅当他上过). 1.POJ 1274 The Perfect Stall http://poj.org/problem?id=1274 和上一题过山车一样,也是二分图匹配的. 水题. #incl…
题意: P门课程,N个学生.给出每门课程的选课学生,求是否可以给每门课程选出一个课代表.课代表必须是选了该课的学生且每个学生只能当一门课程的. 题解: 匈牙利算法的入门题. #include <iostream> #include <cstring> #include <cstdio> #include <vector> using namespace std; ; int t; int k, s; int flag; int p, n; int vis[m…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20478   Accepted: 8056 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
最近学了二分图最大匹配,bfs模板却死活打不出来?我可能学了假的bfs 于是用到了dfs模板 寻找二分图最大匹配的算法是匈牙利算法 匈牙利算法的主要程序是寻找增广路 寻找增光路是过程是:从一个未经配对的点出发,历经未配边.匹配边.未配边.匹配边.未配边....最终到达一个未配点的过程,只要把路径中的未配边和匹配边的“身份”对调,匹配就加一了.这就是一个寻找增广路的过程,通过不断寻找增广路,可以找到最大的匹配. #include<cstdio> #include<cstring> #…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18454   Accepted: 7275 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
(为什么最大独立集的背景都是严打搞对象的( _ _)ノ|壁) 思路:匈牙利算法 没什么可说的-- // by SiriusRen #include <cstdio> #include <cstring> using namespace std; int cases,n,tot,ans,first[555],next[555555],v[555555],fa[555],vis[555]; struct Student{int n;char sex[2],music[105],spor…
Asteroids Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23963   Accepted: 12989 Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K a…
http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<queue> using namespace std; #define LL lon…
题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生相匹配. 受之前第一道匹配题(POJ 1274 The Perfect Stall)的影响,没有仔细体会是从哪个点匹配到哪个点,这将导致Hungary() 和 dfs() 中 for 循环的约束条件,究竟是遍历课程数 P 还是 学生数N,不要搞混!其实从存储的map[i][j] 可以 知道 怎样遍历…
//算法核心是求最大匹配数 #include<bits/stdc++.h> #include<iostream> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<string.h> #define maxint 999999999 using namespace std; ],cy[],edge[][]; ];…
http://poj.org/problem?id=3041 #include <cstdio> #include <cstring> #include <vector> using namespace std; int e[1004][1004]; bool vis[1004]; vector <int > G[1004]; int n,m; int dfs(int s){ vis[s]=true; if(s==n*2+1){//printf("…
                                                                 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21527   Accepted: 8460 Description Consider a group of N students and P courses. Each student visits zero, one or mo…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description Consider a group of N students and P courses. Each student visits zero, one or more than…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16877   Accepted: 6627 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
都是经典题了吧..我好无聊.. 4806 4806-1801是双倍经验..DP方程看代码吧.. /* http://www.cnblogs.com/karl07/ */ #include <cstdlib> #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; #define ll long long //#d…
#include<iostream> #include<cstdio> #include<cstring> #define maxn 2020 using namespace std; int n,m,g[maxn][maxn],ans,f[maxn],match[maxn]; int init() { ;char s;s=getchar(); ')s=getchar(); +s-';s=getchar();} return x; } int Dfs(int s) {…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21515   Accepted: 8455 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
emmmmm 让你敲个匈牙利 #include<cstdio> #include<algorithm> #include<cstring> #define N 510 using namespace std; int adj[N][N],n,k,vis[N],bf[N],cnt; int find(int x) { ;i<=n;i++) if (adj[x][i] && !vis[i]) { vis[i]=; if (!bf[i] || find(…
COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24192   Accepted: 9426 Description Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is poss…
//匈牙利算法-DFS //求最小点覆盖集 == 求最大匹配 //Time:0Ms Memory:208K #include<iostream> #include<cstring> #include<cstdio> #include<algorithm> using namespace std; #define MAX 105 #define INF 0x3f3f3f3f int n,m,k; int gp[MAX][MAX]; bool sx[MAX],s…
博文“二分图的最大匹配.完美匹配和匈牙利算法”对二分图相关的几个概念讲的特别形象,特别容易理解.本文介绍部分主要摘自此博文. 还有其他可参考博文: 趣写算法系列之--匈牙利算法 用于二分图匹配的匈牙利算法 1.前言 二分图:简单来说,如果图中点可以被分为两组,并且使得所有边都跨越组的边界,则这就是一个二分图.准确地说:把一个图的顶点划分为两个不相交集 U 和V ,使得每一条边都分别连接U.V中的顶点.如果存在这样的划分,则此图为一个二分图.二分图的一个等价定义是:不含有「含奇数条边的环」的图.图…
题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反之Tom胜出. 思路:数据比较小,所以我是水过的,模拟过程 + 贪心就能过.但正解是二分图匹配,之前没接触过. 二分图匹配:解释一下第二组样例,k = 2; 从左向右,每一个能够匹配 i 的(a),就去掉 i 周围其他的边,然后再也去掉a能指向的边,计算一下共有几个能匹配的,如果是n,则Jerry胜…
728. [网络流24题] 最小路径覆盖问题 ★★★☆   输入文件:path3.in   输出文件:path3.out   评测插件时间限制:1 s   内存限制:128 MB 算法实现题8-3 最小路径覆盖问题(习题8-13) ´问题描述: 给定有向图G=(V,E).设P是G的一个简单路(顶点不相交)的集合.如果V中每个 顶点恰好在P的一条路上,则称P是G的一个路径覆盖.P中路径可以从V的任何一个顶 点开始,长度也是任意的,特别地,可以为0.G的最小路径覆盖是G的所含路径条数最少 的路径覆盖…
题目链接:http://poj.org/problem?id=1466 Girls and Boys Time Limit: 5000MS   Memory Limit: 10000K Total Submissions: 12026   Accepted: 5355 Description In the second year of the university somebody started a study on the romantic relations between the stu…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课程的学生,求出学生与课程的最大匹配数目,问结果是否与课程数目相同,相同输出YES,否则NO 分析:匈牙利算法 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过) 求解二部图的最大匹配.只要匹配可以盖住每门课程,即匹配数与课程数量相等,委员会就可…
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Description Suppose that we have a square city with straight streets. A map of a city is a square board…
传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (…
http://poj.org/problem?id=3041 在n*n的网格中有K颗小行星,小行星i的位置是(Ri,Ci),现在有一个强有力的武器能够用一发光速将一整行或一整列的小行星轰为灰烬,想要利用这个武器摧毁所有的小行星最少需要几发光束. 主要是构图,将每一行当成一个点,构成集合1,每一列也当成一个点,构成集合2,每一个障碍物的位置坐标将集合1和集合2的点连接起来,也就是将每一个障碍物作为连接节点的边,这样可以得出本题是一个最小点覆盖的问题==二分图的最大匹配. 就可以通过匈牙利算法求解.…