POJ 1417 并查集 dp】的更多相关文章

After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despaired, he was still fortunate to remember a legend of the foggy island, which he had heard…
True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2087   Accepted: 640 Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exha…
思路:很简单的种类并查集,利用并查集可以将所有的人分成几个集合,每个集合又分为好人和坏人集合,直接进行背包dp判断有多少种方法可以在取了所有集合并且人数正好凑足p1个好人的方案.dp(i, j)表示前i和集合有j个好人的方案,如果dp(n, p1)不等于1说明方案不止一种或则根本不存在.注意在dp时,记录路径. AC代码 #include <cstdio> #include <cmath> #include <cctype> #include <algorithm…
题目:http://poj.org/problem?id=1417 题意:输入三个数m, p, q 分别表示接下来的输入行数,天使数目,恶魔数目: 接下来m行输入形如x, y, ch,ch为yes表示x说y是天使,ch为no表示x说y不是天使(x, y为天使,恶魔的编号,1<=x,y<=p+q):天使只说真话,恶魔只说假话: 如果不能确定所有天使的编号,输出no,若能确定,输出所有天使的编号,并且以end结尾: 注意:可能会有连续两行一样的输入:还有,若x==y,x为天使: 思路:种类并查集+…
题目意思是一个图中,只有上下左右四个方向的边.给出这样的一些边, 求任意指定的2个节点之间的距离. 就是看不懂,怎么破 /* POJ 1984 并查集 */ #include <stdio.h> #include <string.h> #include <iostream> #include <algorithm> #include <math.h> using namespace std; ; int F[MAXN]; int dx[MAXN]…
题目链接:http://poj.org/problem?id=1417 Time Limit: 1000MS Memory Limit: 10000K Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore on a foggy island. Though he was exhausted and despair…
题目大意: 一共有p1+p2个人,分成两组,一组p1,一组p2.给出N个条件,格式如下: x y yes表示x和y分到同一组,即同是好人或者同是坏人. x y no表示x和y分到不同组,一个为好人,一个为坏人 这个可以自己分析一下, 很简单. 问分组情况是否唯一,若唯一则输出p1的成员,否则输出no.保证不存在矛盾条件,但是有可能出现x=y的情况. 思路: 参考链接:http://www.cnblogs.com/kuangbin/archive/2013/04/06/3002498.html 用…
题目链接:http://poj.org/problem?id=1417 True Liars Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3851   Accepted: 1261 Description After having drifted about in a small boat for a couple of days, Akira Crusoe Maeda was finally cast ashore…
http://poj.org/problem?id=1797 题意:就是从第一个城市运货到第n个城市,最多可以一次运多少货. 输入的意思分别为从哪个城市到哪个城市,以及这条路最多可以运多少货物. 思路:我觉得可以用floyd来做这道题,结果交上去就TLE了,不过时间复杂度为n3TLE看起来也是比较正常,毕竟数字大. 然后我就看到网上有人用并查集来做,不然以前我都没往这方面想过,然后就用并查集来做 用并查集的思路就是,首先,对每组数据按照重量由大到小进行排序.然后查找合并.当Find(n) ==…
G - A Bug's Life Time Limit:10000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 2492 Appoint description: Description BackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. H…