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. Enhancing Reliability and Response Times via Replication in Computing Clusters---INFOCOM 2015

    [标题] Enhancing Reliability and Response Times via Replication in Computing Clusters [作者] Zhan Qiu an ...

  2. hibernate异常:org.hibernate.NonUniqueObjectException

    异常:org.hibernate.NonUniqueObjectException 提示:a different object with the same identifier value was a ...

  3. QT源码剖析之QSS样式表

    1. "QApplication::setStyleSheet()"设置样式表: 1. 创建新的样式表. 2. 设置新的样式. void QApplication::setStyl ...

  4. Git忽略对特定文件的跟踪和提交

    1.有未提交过的文件,并且此文件项目组中的其他人员也需要忽略,可将此文件的完整路径写入项目文件夹下的.gitignore文件. 2.有未提交过的文件,此这些文件与项目组中的其他人员无关,毋须写入.gi ...

  5. C-Free 5.0编译失败问题解决办法

    解决关于C-Free 5.0编译时提示错误:[Error] undefined reference to `__dyn_tls_init_callback' 解决办法: 因为错误提示的路径是C:\Mi ...

  6. python+selenium+Eclipse安装

    1.安装python 参考安装python:http://www.cnblogs.com/beyongblue/p/4215740.html 2.安装python管理工具setuptools 3.安装 ...

  7. CodeForces 701C They Are Everywhere

    双指针. 先统计一下字符种类数$sum$,然后进行尺取. 如果目前的区间$[L,R]$中不同字符个数$k<sum$,那么区间右端往右移动一位,更新种类数. 如果目前的区间$[L,R]$中不同字符 ...

  8. iOS开发下架在AppStore中销售的app

    1.登陆开发者账号 2.选择itunes connect 选择我的app 3.选择要下架的app 4.价格与销售范围 5.销售范围 6.点击存储 //如果想要重新在AppStore中进行销售只需要选择 ...

  9. HDU3791二叉搜索树(二叉树)

    Problem Description 判断两序列是否为同一二叉搜索树序列   Input 开始一个数n,(1<=n<=20) 表示有n个需要判断,n= 0 的时候输入结束.接下去一行是一 ...

  10. 【转】js获取url传递参数

    <Script language="javascript">var Request = new Object();Request = GetRequest();var ...