博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5506 GT and set(dfs爆搜)
阅读量:6882 次
发布时间:2019-06-27

本文共 3045 字,大约阅读时间需要 10 分钟。

Problem Description
You are given
 N sets.The ith set has Ai numbers.
You should divide the sets into L parts.
And each part should have at least one number in common.
If there is at least one solution,print YES,otherwise print NO.
 

 

Input
In the first line there is the testcase
 T (T20)
For each teatcase:
In the first line there are two numbers N and L.
In the next N lines,each line describe a set.
The first number is Ai,and then there are Ai distict numbers stand for the elements int the set.
The numbers in the set are all positive numbers and they're all not bigger than 300.
1N301L51Ai101LN
You'd better print the enter in the last line when you hack others.
You'd better not print space in the last of each line when you hack others.
 

 

Output
For each test print
 YES or NO
 

 

Sample Input
2 2 1 1 1 1 2 3 2 3 1 2 3 3 4 5 6 3 2 5 6
 

 

Sample Output
NO YES
Hint
For the second test,there are three sets:{1,2,3},{4,5,6},{2,5,6} You are asked to divide into two parts. One possible solution is to put the second and the third sets into the same part,and put the first in the other part. The second part and the third part have same number 6. Another solution is to put the first and the third sets into the same part,and put the second in the other part.
 

题意:

有n个集合,问你能否在L次内把所有集合都删去,如果两个或者更多集合内含有一个相同的数,则这些集合可以同时删除

每个集合中的元素小于10,L<=5,n<=30

分析:

由于数据范围都比较小,很容易想到搜索

很容易想到可以枚举当前集合应该删除哪个数,如果下一个集合中已经出现过了这个数,则跳过下一个集合,可以选择的删除的数不超过5个

每个集合中最多有10个数能被选择,所以时间复杂度也就为10^5*n,乘以n是因为要判断需不需要从当前这个集合中删除一个数

 

首先贴上第一个代码,这个代码在oj上能AC,但是题目给出的样例中的第一个样例却过不来。和下面贴出的第二个样例写得差不多,但就是样例有一个过不了,不懂什么原因。

1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 #define ll long long16 #define eps 1e-1017 #define MOD 100000000718 #define N 3619 #define M 30620 #define inf 1e1221 int n,L;22 vector
g[N];23 int s[N];24 int vis[M];25 int flag;26 bool judge(int num){27 for(int i=0;i
=n){37 flag=1;38 return;39 }40 if(judge(num)){41 dfs(num+1,d);42 }43 if(flag){44 return;45 }46 47 if(d>L){48 return;49 }50 51 for(int i=0;i
View Code

 

第二个代码,正确。

1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 #define ll long long16 #define eps 1e-1017 #define MOD 100000000718 #define N 3619 #define M 30620 #define inf 1e1221 int n,L;22 vector
g[N];23 int s[N];24 int vis[M];25 int flag;26 bool judge(int num){27 for(int i=0;i
=n){38 //flag=1;39 return true;40 }41 if(judge(num)){42 return dfs(num+1,d);43 }44 //if(flag) return;45 if(d>=L) return false;46 for(int i=0;i
View Code

 

转载地址:http://hknbl.baihongyu.com/

你可能感兴趣的文章
Vc控件用法总结之List Control
查看>>
[转] 【开源访谈】Muduo 作者陈硕访谈实录
查看>>
LeetCode 86. Partition List 20170612
查看>>
我的XHTML学习笔记
查看>>
单链表的增删查改
查看>>
centos7系统安装python3,pip3,django
查看>>
php观察者模式
查看>>
励志名言
查看>>
Linux基本命令 文件搜索命令
查看>>
C#点击按钮用DataGridView动态增加行、删除行,增加按钮列
查看>>
重构的信号
查看>>
如何计算团队贡献
查看>>
图片特效处理之怀旧效果
查看>>
MySQL5.7主从,单slave多master
查看>>
51nod 1304 字符串的相似度(exkmp)
查看>>
Frameset使用教程
查看>>
cocos-lua
查看>>
jdk的安装与配置
查看>>
Python数据抓取技术与实战 pdf
查看>>
20145209 《信息安全系统设计基础》第3周学习总结
查看>>