hdu 5506 GT and set dfs+bitset优化
GT and set
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
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.
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.
1≤N≤30,1≤L≤5,1≤Ai≤10,1≤L≤N
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.
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.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
const int N=2e5+,M=1e6+,inf=1e9+;
const ll INF=1e18+,mod=;
bitset<> flag[],a[],temp,bit;
int n,m,ans;
void dfs(int pos)
{
if(pos>n||ans)
{
ans=;
return;
}
for(int i=;i<=m;i++)
{
temp=flag[i]&a[pos];
bit=flag[i];
if(temp.count())
{
flag[i]=temp;
dfs(pos+);
flag[i]=bit;
}
}
}
void init()
{
for(int i=;i<=n;i++)
a[i].reset();
for(int i=;i<=m;i++)
flag[i].set();
ans=;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
init();
for(int i=;i<=n;i++)
{
int z;
scanf("%d",&z);
for(int j=;j<=z;j++)
{
int x;
scanf("%d",&x);
a[i].set(x);
}
}
dfs();
if(ans)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
hdu 5506 GT and set dfs+bitset优化的更多相关文章
- HDU 5808 Price List Strike Back bitset优化的背包。。水过去了
http://acm.hdu.edu.cn/showproblem.php?pid=5808 用bitset<120>dp,表示dp[0] = true,表示0出现过,dp[100] = ...
- 洛谷P1441 砝码称重(搜索,dfs+bitset优化)
洛谷P1441 砝码称重 \(n\) 的范围为 \(n \le 20\) ,\(m\) 的范围为 \(m \le 4\) . 暴力遍历每一种砝码去除情况,共有 \(n^m\) 种情况. 对于剩余砝码求 ...
- HDU 5506:GT and set bitset+暴力
GT and set Accepts: 35 Submissions: 194 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 655 ...
- HDU 5890 Eighty seven(DP+bitset优化)
题目链接 Eighty seven 背包(用bitset预处理)然后对于每个询问O(1)回答即可. 预处理的时候背包. #include <bits/stdc++.h> using nam ...
- Hdu 6268 点分治 树上背包 bitset 优化
给你一颗大小为n(3000)的树,树上每个点有点权(100000),再给你一个数m(100000) i为1~m,问树中是否存在一个子图,使得权值为i. 每次solve到一个节点 用一个bitset维护 ...
- hdu 5745 La Vie en rose DP + bitset优化
http://acm.hdu.edu.cn/showproblem.php?pid=5745 这题好劲爆啊.dp容易想,但是要bitset优化,就想不到了. 先放一个tle的dp.复杂度O(n * m ...
- HDU - 6268: Master of Subgraph (分治+bitset优化背包)
题意:T组样例,给次给出一个N节点的点权树,以及M,问连通块的点权和sum的情况,输出sum=1到M,用0或者1表示. 思路:背包,N^2,由于是无向的连通块,所以可以用分治优化到NlgN. 然后背包 ...
- hdu 5036 Explosion bitset优化floyd
http://acm.hdu.edu.cn/showproblem.php?pid=5036 题意就是给定一副有向图,现在需要走遍这n个顶点,一开始出发的顶点是这n个之中的随便一个. 如果走了1,那么 ...
- hdu 4109 dfs+剪枝优化
求最久时间即在无环有向图里求最远路径 dfs+剪枝优化 从0节点(自己添加的)出发,0到1~n个节点之间的距离为1.mt[i]表示从0点到第i个节点眼下所得的最长路径 #include<iost ...
随机推荐
- centos6.4 挂载新盘并移动mysql数据目录
1 centos 挂载新盘并格式化 以vmware workstation12 中安装的centos6. 虚拟机为例进行演示 关机,添加硬盘 开机,格式化硬盘,并挂载 通过命令查看硬盘 fdisk – ...
- C# 利用SQLite对.DB和.logdb加密和解密和SQLite创建数据库
1.最近研究了下利用SQLite为db文件简单的加密和解密 private static SQLiteConnection GetConnection() { SQLiteConnection con ...
- echarts 用marlkline画线 同时配置中含有datazoom,怎么设置markline
由于项目需要设置边界值即用markline 画标线,通过echarts文档可以查看到(如下) 1.通过坐标点(xAxis和yAxis的设置) 通过网上搜索许多markline的配置都是通过下面来设置的 ...
- javaSE基础第二篇
1.JDK下载: www.oracle.com 2.JAVA_HOME bin目录:存放可执行文件.exe 把可能变的路径写入JAVA_HOME path=......;%JAVA_HOME%%; ...
- 1.NoSql简介
NoSQL,指的是非关系型的数据库.随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发的SNS类型的web2.0纯动态网站已经显得力不从心,暴露了很多难以 ...
- Java多线程开发系列之四:玩转多线程(线程的控制1)
在前文中我们已经学习了:线程的基本情况.如何创建多线程.线程的生命周期.利用已有知识我们已经可以写出如何利用多线程处理大量任务这样简单的程序.但是当应用场景复杂时,我们还需要从管理控制入手,更好的操纵 ...
- Linux主机规划
当你想装linux操作系统的时候,一定要知道你的用途,不同的用途就要规划不同的装机方式. 首先要知道一些概念: 挂载:利用一个目录当成进入点,将磁盘分区的数据放置在该目录下. 磁盘第一个扇区记录的信息 ...
- C# 不重复的随机数
public int RabdomNumber() { num = new Random(Guid.NewGuid().GetHashCode()).Next(0, 40); return num; ...
- Flexbox布局(转)
Flexbox布局( Flexible Box 或CSS3 弹性布局),是CSS3中的一种新的布局模式,是可以自动调整子元素的高和宽,来很好的填充任何不同屏幕大小的显示设备中的可用显示空间,收缩内容防 ...
- Makefile编译库
funs.h: #ifndef __FUNS_H__ #define __FUNS_H__ void fun1(); #endif funs.c #include "funs.h" ...