二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdin); #define FOPO freopen("out.txt", "w", stdout); using namespace std; typedef long long LL; + ; int n, k, x, y; int link[maxn], vis[ma…
d.一颗树,选最少的点覆盖所有边 s. 1.可以转成二分图的最小点覆盖来做.不过转换后要把匹配数除以2,这个待细看. 2.也可以用树形dp c.匈牙利算法(邻接表,用vector实现): /* 用STL中的vector建立邻接表实现匈牙利算法 效率比较高 处理点比较多的效率很高.1500的点都没有问题 */ #include<iostream> #include<stdio.h> #include<algorithm> #include<string.h>…
<题目链接> 题目大意:鲍勃喜欢玩电脑游戏,特别是战略游戏,但有时他无法找到解决方案,速度不够快,那么他很伤心.现在,他有以下的问题.他必须捍卫一个中世纪的城市,形成了树的道路.他把战士的最低数量的节点上,使他们可以观察所有的边.你能帮助他吗?士兵,鲍勃把一个给定的树,你的程序应该发现的最小数目. 解题分析: 最小点覆盖模板题,用最少的点来覆盖所有的边.建立无向图,然后求出其最大匹配,最小点覆盖数=最大匹配数.需要注意的是,本题用邻接矩阵存图跑匈牙利会T,所以用链式前向星存图. #includ…
分析:这里使用树形DP做. 1.最小顶点覆盖做法:最小顶点覆盖 == 最大匹配(双向图)/2. 2.树形DP: dp[i][0]表示i为根节点,而且该节点不放,所需的最少的点数. dp[i][1]表示i为根节点,而且该节点放,所须要的最少的点数. dp[i][0]=sum(dp[son[i][j]][1]) 该点不放.则它的儿子节点必须都放,仅仅有这样之间的边才干够被覆盖. dp[i][1]=sum(min(dp[son[i][j]][0],dp[son[i][j]][1])) 该点放的话,则它…
( ̄▽ ̄)" //凡无向图,求匹配时都要除以2 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> #include<vector> using namespace std; ; int uN; vector<int> g[MAXN]; int link[MAXN]; bool vis[MAXN]; bool DFS(int u)…
http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判断是否能行. 思路:二分图匹配的模板题. #include<iostream> #include<cstdio> #include<cstring> using namespace std; int p, n; ][]; ]; ]; //第i学生的选课 int dfs(in…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1054 题目大意:给你一棵树,选取树上最少的节点使得可以覆盖整棵树. 解题思路: 首先树肯定是二分图,因为树可以奇偶分层,从而根据二分图染色的原理可以确定树是二分图.我们可以用染色法确定出两个集合求最大匹配,也可以将边补成双向的,然后将最大匹配/2. 代码: #include<iostream> #include<cstdio> #include<cstring> #incl…
onsider 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 satisfies simultaneously the conditions: . every stud…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4697    Accepted Submission(s): 2125 Problem Description Bob enjoys playing computer games, especially strategic games, but somet…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 8504    Accepted Submission(s): 4094 Problem Description Bob enjoys playing computer games, especially strategic games, but some…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 10035    Accepted Submission(s): 4691 Problem Description Bob enjoys playing computer games, especially strategic games, but some…
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=106048#problem/B 题意:给出一些点相连,找出最小的点数覆盖所有的 用树形dp来解决 dp[i][0]表示i点不选,dp[i][1]表示i点选,dp[i][0] = sum{ dp[ son[i] ][1] }, // i不选,则i的子节点全选, dp[i][1] = sum { min( dp[ son[i] ][0], dp[ son[i] ][1] ) } +…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6586    Accepted Submission(s): 3066 Problem Description Bob enjoys playing computer games, especially strategic games, but some…
Problem Description Bob enjoys playing computer games, especially strategic games, but sometimes he cannot find the solution fast enough and then he is very sad. Now he has the following problem. He must defend a medieval city, the roads of which for…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2925    Accepted Submission(s): 1222 Problem Description Bob enjoys playing computer games, especially strategic games, but somet…
 最小点覆盖概念:选取最小的点数覆盖二分图中的所有边. 最小点覆盖 = 最大匹配数. 证明:首先假设我们求的最大匹配数为m,那么最小点覆盖必然 >= m,因为仅仅是这m条边就至少需要m个点.然后假如我们已经求得最小覆盖点集,那么在点集中每个点必然有着这样的性质,在于它相连的边里面,一定有一条边的端点不在最小点集中,因为如果连一条这样的边都没有,那这个点完全没有在最小点集的必要,我们任意选取这样的一条边,一定可以形成一个匹配,匹配数与最小点集中的点的个数相等,但现在这仅仅是一个匹配,他必然小于最大…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4061    Accepted Submission(s): 1791 Problem Description Bob enjoys playing computer games, especially strategic games, but some…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3806    Accepted Submission(s): 1672 Problem Description Bob enjoys playing computer games, especially strategic games, but some…
题目链接 题意: 给一颗树,用最少的点覆盖整棵树. 每一个结点可以防守相邻的一个边,求最少的点防守所有的边. 分析: 1:以当前节点为根节点,在该节点排士兵守护道路的最小消耗.在这种情况下,他的子节点可以安排士兵,也可以不安排士兵.可以从各个子节点两个不同状态(存在士兵,不存在士兵)的最值中选出最小的消耗,然后相加就求出了当前节点派士兵的最小消耗. 2:以当前节点为根节点,不存在士兵.这种情况十分清楚,因为当前节点没有士兵,那么这个节点到子节点之间的道路没有人守护,那么子节点就必须要安排士兵,因…
过山车Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10683    Accepted Submission(s): 4699 Problem DescriptionRPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩, 就是每个女生必须找个个男生做part…
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 863    Accepted Submission(s): 342 Problem Description Kaname Mado…
题目链接 F(N) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4579 Accepted Submission(s): 1610 Problem Description Giving the N, can you tell me the answer of F(N)? Input Each test case contains a si…
题目大意:有两个机器A和B,A机器有n个模式,B机器有m个模式,两个机器最初在0模式 然后有k个作业,每个作业有三个参数i,a,b i代表作业编号,a和b代表第i作业要么在A机器的a模式下完成[或者]在B机器的b模式下完成 问两个机器总共最少变换多少次可以完成所有作业 简单的二分图裸题,但是要注意使用邻接表的时候加上对于b机器初始模式0的判断 而且题上还有数据的问题,有一个点k的值比题中描述大(我开5000过的) #include<iostream> #include<cstdio>…
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 (1 <= K <= 10,000), which are conveniently located at the lattice points of the grid. Fortun…
题面 RPG girls今天和大家一起去游乐场玩,终于可以坐上梦寐以求的过山车了.可是,过山车的每一排只有两个座位,而且还有条不成文的规矩,就是每个女生必须找个个男生做partner和她同坐.但是,每个女孩都有各自的想法,举个例子把,Rabbit只愿意和XHD或PQK做partner,Grass只愿意和linle或LL做partner,PrincessSnow愿意和水域浪子或伪酷儿做partner.考虑到经费问题,boss刘决定只让找到partner的人去坐过山车,其他的人,嘿嘿,就站在下面看着…
http://acm.hdu.edu.cn/showproblem.php?pid=1054 Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 8510    Accepted Submission(s): 4096 Problem Description Bob enjoys playing computer games, espec…
Strategic Game Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7651    Accepted Submission(s): 3645 Problem Description Bob enjoys playing computer games, especially strategic games, but somet…
题意:用最小的点来覆盖全部的边,因为二分图里面最大的匹配就是最小覆盖,所以直接匹配一下即可 *********************************************************************** #include<stdio.h> #include<; ; ];;     memset(Head, -, , , ; i<N; i++)     {          )         {             dx[i] = ; j=e[j…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 12323   Accepted: 6716 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 (1…
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 satisfies simultaneously the conditions: . every stu…