HDU 5823 color II
dp[i]表示i子图的最小染色数目。
dp[i]=min( dp[i], dp[j]+1 ), j是i的子集,并且j图内的点没有边相连。
高效率枚举i子集的方法:for(int j=i;j;j=(j-1)&i) 每一个j都是i的子集。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-;
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
}
inline int read()
{
char c = getchar(); while(!isdigit(c)) c = getchar(); int x = ;
while(isdigit(c)) { x = x * + c - ''; c = getchar(); }
return x;
} const int maxn=;
char s[maxn];
int T,n,e[],f[];
bool t[];
LL mod=((LL)<<); LL POW(LL a,LL b,LL MOD){
LL ret=;
while(b){ if(b&) ret=(ret*a)%MOD; a=(a*a)%MOD; b>>=; }
return ret;
} int main()
{
scanf("%d",&T); while(T--)
{
scanf("%d",&n);
memset(e,,sizeof e); memset(t,,sizeof t);
for(int i=;i<n;i++)
{
scanf("%s",s);
for(int j=;s[j];j++) if(s[j]=='') e[i]=e[i]|(<<j);
}
t[]=;
for(int i=;i<(<<n);i++)
{
if(t[i]==) continue;
int state=i; for(int j=;j<n;j++) if(i&(<<j)) state=state|e[j];
for(int j=;j<n;j++) if(!(state&(<<j))) t[i|(<<j)]=;
} f[]=;
for(int i=;i<(<<n);i++)
{
f[i]=;
for(int j=i;j;j=(j-)&i) if(t[j]) f[i]=min(f[i],f[i^j]+);
} LL ans=,P=;
for(int i=;i<(<<n);i++) ans=(ans+f[i]*P%mod)%mod, P=P*%mod;
printf("%lld\n",ans);
}
return ;
}
HDU 5823 color II的更多相关文章
- HDU 5823 color II(FWT)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5823 [题目大意] 定义一张无向图的价值:给每个节点染色使得每条边连接的两个节点颜色不相同的最少颜 ...
- hdu 5823 color II —— 子集DP
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5823 看博客:http://www.cnblogs.com/SilverNebula/p/5929550. ...
- hdu 5823 color II——子集dp(独立集)
题目:http://acm.hdu.edu.cn/showproblem.php?pid=5823 独立集染一种颜色.在这个基础上枚举子集来dp. 状压一样地存边真是美妙. 2^32是1ll<& ...
- hdu 5823 color II 状压dp
题目链接 给n个点 n<=18. 然后给出它们两两之间是否有边相连. 问你这个图的所有子集,最少要用多少种颜色来染色, 如果两个点相连, 那么这两个点不能染同样的颜色. 先预处理出所有的点独立集 ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 5823 (状压dp)
Problem color II 题目大意 定义一个无向图的价值为给每个节点染色使得每条边连接的两个节点颜色不同的最少颜色数. 对于给定的一张由n个点组成的无向图,求该图的2^n-1张非空子图的价值. ...
- HDU 3567 Eight II(八数码 II)
HDU 3567 Eight II(八数码 II) /65536 K (Java/Others) Problem Description - 题目描述 Eight-puzzle, which is ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
随机推荐
- android设备中USB转串口demo 下载
http://files.cnblogs.com/guobaPlayer/testUSB2Serial.apk USB转串口demo程序, 无需驱动,只要手机USB是OTG类型,插上我们的模块即可使用 ...
- nodejs 实现简单的文件上传功能
首先需要大家看一下目录结构,然后开始一点开始我们的小demo. 文件上传总计分为三种方式: 1.通过flash,activeX等第三方插件实现文件上传功能. 2.通过html的form标签实现文件上传 ...
- HttpHelps类
/// <summary> /// 类说明:HttpHelps类,用来实现Http访问,Post或者Get方式的,直接访问,带Cookie的,带证书的等方式,可以设置代理 /// 重要提示 ...
- Qt实现悬浮窗效果
当鼠标移动到头像控件时,显示悬浮窗,当鼠标离开时,悬浮窗隐藏. 1.控件选择 悬浮窗可以从QDialog派生,并将窗口的属性设置为无边框 this->setWindowFlags(this- ...
- pychon - selenium2Libray源码简介
I. Introduction Selenium2Library是robot framework中主流的测试网页功能的库, 它的本质是对webdriver的二次封装, 以适应robot框架. 百度上一 ...
- Design Pattern——单一职责原理
在类的职责分离上多考虑,做到单一职责,这样的代码才能做到易于维护,易扩展,灵活多样.
- Finish and error to: Error Domain=NSURLErrorDomain Code=-1001 "请求超时。
错误显示:Finish and error to: Error Domain=NSURLErrorDomain Code=-1001 "请求超时." UserInfo={NSUnd ...
- CSU 1640 机智的刷题方式
完全背包 #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> ...
- hdu 1217 Arbitrage
Flody多源最短路 #include<cstdio> #include<cstring> #include<string> #include<cmath&g ...
- [妙味JS基础]第十二课:数组随机、数组去重
知识点总结 json var json={'name':'abc'} 属性加分号为安全的写法 json: 只能用for in 数组:for和for in 都可以使用 json没有length和下标 数 ...