题意

n头牛,m个房间,每头牛有自己喜欢的房间,问每头牛都住进自己喜欢的房间有多少种分配方法?

Input

In the first line of input contains two integers N and M (1 <= N <= 20, 1 <= M <= 20). Then come N lines. The i-th line first contains an integer P (1 <= P <= M) referring to the number of barns cow i likes to play in. Then follow P integers, which give the number of there P barns.

Output

Print a single integer in a line, which is the number of solutions.
Sample Input

3 4
2 1 4
2 1 3
2 2 4

Sample Output

4
Analysis
首先,这种数据我们很容易想到是状压DP
我们可以比较轻松的写出状态转移方程
if(status&(1<<room)==0)
  dp[i][status|(1<<room)]+=dp[i-1][status];
但是我们发现这样是会MLE的,我们就可以采用滚动数组,或是直接上一维
一维要注意status从大到小循环,因为是每次小的更新大的,status用完之后要清零。
Code
 #include<set>
#include<map>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define RG register int
#define rep(i,a,b) for(RG i=a;i<=b;++i)
#define per(i,a,b) for(RG i=a;i>=b;--i)
#define ll long long
#define inf (1<<29)
using namespace std;
int n,m,ans;
int a[][];
int dp[];
inline int read()
{
int x=,f=;char c=getchar();
while(c<''||c>''){if(c=='-')f=-;c=getchar();}
while(c>=''&&c<=''){x=x*+c-'';c=getchar();}
return x*f;
} int main()
{
n=read(),m=read();
rep(i,,n)
{
a[i][]=read();
rep(j,,a[i][])
a[i][j]=read();
}
dp[]=;
rep(i,,n)
{
per(j,(<<m)-,)
{
if(!dp[j]) continue;
rep(k,,a[i][])
{
if(!(j&(<<(a[i][k]-))))
{
dp[j|(<<(a[i][k]-))]+=dp[j];
}
}
dp[j]=;
}
}
int ans=;
per(j,(<<m)-,) ans+=dp[j];
cout<<ans;
return ;
}

Arrange the Bulls [POJ2441] [状压DP]的更多相关文章

  1. POJ2441 Arrange the Bulls(状压DP)

    题目是,有n头牛,每头牛都喜爱某几个草地,要把这n头牛分配给m个不同的它们喜爱的草地,问有几种分配方式. dp[n][S]表示前n头牛分配完毕后占用的草地集合是S的方案数 dp[0][0]=1 dp[ ...

  2. POJ 2441 Arrange the Bulls(状压DP)

    [题目链接] http://poj.org/problem?id=2441 [题目大意] 每个人有过个喜欢的篮球场地,但是一个场地只能给一个人, 问所有人都有自己喜欢的场地的方案数. [题解] 状态S ...

  3. HDU 1074 Doing Homework【状压DP】

    Doing Homework Problem Description Ignatius has just come back school from the 30th ACM/ICPC. Now he ...

  4. Doing Homework HDU - 1074 (状压dp)

    Ignatius has just come back school from the 30th ACM/ICPC. Now he has a lot of homework to do. Every ...

  5. 【状压DP】【HDOJ1074】

    http://acm.hdu.edu.cn/showproblem.php?pid=1074 Doing Homework Time Limit: 2000/1000 MS (Java/Others) ...

  6. ZOJ 3777 - Problem Arrangement - [状压DP][第11届浙江省赛B题]

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3777 Time Limit: 2 Seconds      Me ...

  7. dp,状压dp等 一些总结

    也就作业几题而已,分析一下提醒 最重要的就是,记住,没用的状态无论怎么转移最后都会是没用的状态,所以每次转移以后的有值的状态都是有用的状态. 几种思考方向: 第一种:枚举当前的状态,转移成另外一个状态 ...

  8. kuangbin专题十二 HDU1074 Doing Homework (状压dp)

    Doing Homework Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. ZOJ - 3777(状压dp)

    The 11th Zhejiang Provincial Collegiate Programming Contest is coming! As a problem setter, Edward i ...

随机推荐

  1. jenkins持续集成原理

    转载: 原文地址:http://www.2cto.com/kf/201609/544550.html 持续集成 开发中,我们经常遇到一些奇怪问题,比如本地可以编译成功的代码但是同事们更新代码后编译出错 ...

  2. deepin 下安装goland中文字体显示全是方块

    下载中文字体 apt-get install ttf-arphic-uming xfonts-intl-chinese 替换goland的汉化包,两个jar包.https://blog.csdn.ne ...

  3. Correction suggestions

    1. title: A remark on the global existence of weak solutions to the compressible quantum Navier-Stok ...

  4. [物理学与PDEs]第2章第4节 激波 4.1 间断连接条件

    1.  守恒律方程 $$\bex \cfrac{\p f}{\p t}+\cfrac{\p q}{\p x}=0 \eex$$ 在间断线上应满足 ``间断连接条件'': $$\bex [f]\cfra ...

  5. [物理学与PDEs]第2章第2节 粘性流体力学方程组 2.2 应力张量

    1.  在有粘性的情形, 外界流体对 $\Omega$ 的作用力, 不仅有表面上的压力 (正压力), 也有表面上的内摩擦力 (切应力). 2.  于 $M$ 处以 ${\bf n}$ 为法向的单位面积 ...

  6. SQL Server 数据库编程技巧

    Ø  简介 本文主要介绍 SQL Server 数据库在平常的开发中,可能会涉及到的编程技巧,主要包含以下内容: 1.   解决 SQL Server 不支持 127.0.0.1 登录 2.   查询 ...

  7. Iterate over slices of a string

    def iter_slices(string, slice_length): """Iterate over slices of a string."" ...

  8. windows 下 bat 计划任务删除保留时间内文件

    date  windows 打印时间戳  年:echo %date:~,% 月:echo %date:~,% 日:echo %date:~,% 星期:echo %date:~,% 小时:echo %t ...

  9. uploadPreview上传图片前预览图片

    uploadPreview.js是一款图片上传前的预览插件.谷歌.火狐.IE都可以兼容,但是不支持safari. 相关的html代码: <!DOCTYPE html PUBLIC "- ...

  10. LOJ #556. 「Antileaf's Round」咱们去烧菜吧

    好久没更博了 咕咕咕 现在多项式板子的常数巨大...周末好好卡波常吧.... LOJ #556 题意 给定$ m$种物品的出现次数$ B_i$以及大小$ A_i$ 求装满大小为$[1..n]$的背包的 ...