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. List集合对象中的排序,随机显示

    List<User> students = new ArrayList<User>(); User user1 = new User(); user1.setAge(112); ...

  2. js 仿 asp中的 asc 和 chr 函数的代码

    <script type="text/javascript">var str;var asc; str = "A";document.write(s ...

  3. freemarker + spring mvc + spring + mybatis + mysql + maven项目搭建

    今天说说搭建项目,使用freemarker + spring mvc + spring + mybatis + mysql + maven搭建web项目. 先假设您已经配置好eclipse的maven ...

  4. 配置 Apache 的虚拟主机

    1.在host配置比如: 找到记事本以管理员的身份打开,然后文件->打开  C:\Windows\System32\drivers\etc    下面的hosts文件 127.0.0.1 www ...

  5. C++中int转为char 以及int 转为string和string 转int和空格分隔字符串

    1.对于int 转为char 直接上代码: 正确做法: void toChar(int b) { char u; ]; _itoa( b, buffer, ); //正确解法一 u = buffer[ ...

  6. 关于linux修改max user processes limits的问题

    我们都知道,ulimit -u 可以设置max user processes limits,但是往往在设置的过程中,这样直接修改,不仅只能临时生效,重启之后又无效了,而且老是会失败. 而一般来说,修改 ...

  7. HDU2571 命运 动态规划

    好久没更新博客了. 校内练习的一道水题 HDU2571 命运. 简单DP. 穿过幽谷意味着离大魔王lemon已经无限接近了!  可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫 ...

  8. kernel Makefile Kconfig说明

    实际文档位置:Documentation/kbuild/makefiles.txt,此为翻译稿. *************************************************** ...

  9. springMVC+Java验证码完善注册功能

    这篇文章简单的写了一个java验证码,为之前写过的springMVC注册功能加上验证码,验证码的作用就不多说了,防止机器人程序恶意注册什么的.. 其中User.java,加上了password和cod ...

  10. Spring Security(05)——异常信息本地化

    Spring Security支持将展现给终端用户看的异常信息本地化,这些信息包括认证失败.访问被拒绝等.而对于展现给开发者看的异常信息和日志信息(如配置错误)则是不能够进行本地化的,它们是以英文硬编 ...