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的更多相关文章

  1. HDU 5823 color II(FWT)

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5823 [题目大意] 定义一张无向图的价值:给每个节点染色使得每条边连接的两个节点颜色不相同的最少颜 ...

  2. hdu 5823 color II —— 子集DP

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5823 看博客:http://www.cnblogs.com/SilverNebula/p/5929550. ...

  3. hdu 5823 color II——子集dp(独立集)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=5823 独立集染一种颜色.在这个基础上枚举子集来dp. 状压一样地存边真是美妙. 2^32是1ll<& ...

  4. hdu 5823 color II 状压dp

    题目链接 给n个点 n<=18. 然后给出它们两两之间是否有边相连. 问你这个图的所有子集,最少要用多少种颜色来染色, 如果两个点相连, 那么这两个点不能染同样的颜色. 先预处理出所有的点独立集 ...

  5. hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  6. hdu 1556:Color the ball(线段树,区间更新,经典题)

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  7. HDU 5823 (状压dp)

    Problem color II 题目大意 定义一个无向图的价值为给每个节点染色使得每条边连接的两个节点颜色不同的最少颜色数. 对于给定的一张由n个点组成的无向图,求该图的2^n-1张非空子图的价值. ...

  8. HDU 3567 Eight II(八数码 II)

    HDU 3567 Eight II(八数码 II) /65536 K (Java/Others)   Problem Description - 题目描述 Eight-puzzle, which is ...

  9. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

随机推荐

  1. 10s后自动跳转

    <div class="jf_register"> <h2>您好,欢迎光临<fmt:message key="b2cShowName&quo ...

  2. java-jvisualvm远程监控tomcat

    一.修改要访问的远程主机(Linux)相关文件,本文档只介绍了java-jvisualvm的JMX方式: 1.打开$CATALINA_HOME/bin/startup.sh, 找到倒数第二行(也就是e ...

  3. OOP in JS Public/Private Variables and Methods

    Summary private variables are declared with the 'var' keyword inside the object, and can only be acc ...

  4. invalid receiver type

    Because in a case like this: type I int type P *I func (i I) Get() int { return int(i) } func (p P) ...

  5. mybatis的decimal精度缺失

    在mybatis里面用decimal确实方便,但是经过测试发现decimal默认只有一位小数,所以也不能滥用,如果是double类型的话还是要使用double

  6. When Hybrid Cloud Meets Flash Crowd: Towards Cost-Effective Service Provisioning--INFOCOM 2015

    [标题] [作者] [来源] [对本文评价] [why] 存在的问题 [how] [不足] assumption future work [相关方法或论文] [重点提示] [其它]

  7. 大学二三事——那些事(1)

    虽然另外一个队友早上忽然拉肚子没有办法去了,我个阿骚还是决定出发. 本来以为早点过去签到可以躲过李导,没想到在她上班的路上被她撞见.   坐在早上那班发往周至县的客车的时候,天气忽好忽坏.   从周至 ...

  8. 《JS权威指南学习总结--6.4检测属性》

    内容要点: js对象可以看做属性的集合,我们经常会检测集合中成员的所属关系-----判断某个属性是否存在于某个对象中,可以通过in运算符,hasOwnPreperty()和propertyIsEnum ...

  9. EasyuiAPI:基础

    一.EasyLoader(简单加载) locale属性:值类型是string locales属性:值类型是object 二.Draggable(拖动) 1.通过标签创建: <div id=&qu ...

  10. boostrap插件

    第一章:模态弹出框 一.导入JavaScript插件 Bootstrap的JavaScript插件可以单独导入到页面中,也可以一次性导入到页面中.因为在Bootstrap中的JavaScript插件都 ...