题意

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. 11.11CTF答案

    签到题                             flag{0ca175b9c0f726a831d895e269332461 } 下载WIN HEX,用WIN HEX打开“海贼王图片”, ...

  2. 3173. 【GDOI2103模拟3.17】扫雷游戏(搜索 + 剪枝)

    Problem 给出一个类似扫雷的游戏,有\(num\)个数字,求至少有多少个雷. Data constraint \(n,m\le 15,num\le 15\) Solution 好搜索啊. 现讲一 ...

  3. win7 远程连接服务器出现身份验证错误,又找不到加密Oracle修正

    今天想用远程桌面连接登录服务器,结果,弹出一个错误的提示框:发生身份验证错误,要求的函数不受支持. 然后在网上找了相关的教程,基本上所有的方法都是如下所示: 策略路径:"计算机配置" ...

  4. [译]Ocelot - Routing

    原文 Ocelot主要的功能就是将http请求转发到对应的下游服务上去. Ocelot将一个请求路由到另外一个路由的动作叫做ReRoute.为了能让Ocelot能正常工作,需要在配置中设置ReRout ...

  5. 【linux】基础知识

    为什么学习Linux? 服务器大多数都是linux操作系统,学习[上线][运维]是我们前端开发工程师的必备技能.Linux系统和maxOS系统十分类似,所以推荐大家使用max电脑工作. Linux的版 ...

  6. Mysql的跨服务器 关联查询--Federated引擎

    1.确认开启Federated引擎     查询FEDERATED功能是否开启: show ENGINES;       2.如果状态为NO则需修改my.ini文件,增加一行federated配置: ...

  7. Leetcode#521. Longest Uncommon Subsequence I(最长特殊序列 Ⅰ)

    题目描述 给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列). 子序列可以通过删去字符串中的某些字符实现,但 ...

  8. vue学习之组件

    组件从注册方式分为全局组件和局部组件. 从功能类型又可以分为偏视图表现的(presentational)和偏逻辑的(动态生成dom),推荐在前者中使用模板,在后者中使用 JSX 或渲染函数动态生成组件 ...

  9. jenkins结合gitlab实现提交代码自动构建

    jenkins可以说是现在非常流行的一个继续集成工具,几乎所有的公司都在用,并且它也基本是devops的连接者,是一个比较核心的工具. 主要记录以下两个: 利用jenkins和gitlab的webho ...

  10. 【原创】大数据基础之Mesos(1)简介、安装、使用

    Mesos 1.7.1 官方:http://mesos.apache.org/ 一 简介 Program against your datacenter like it’s a single pool ...