题意

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. Matlab中hold on与hold off的用法

    摘录自:https://blog.csdn.net/smf0504/article/details/51830963 https://www.cnblogs.com/shuqingstudy/p/48 ...

  2. JAVA实现C/S结构小程序

    程序功能: 客户端向服务器发送一个本地磁盘中的文件, 服务器程序接受后保存在其他位置. 客户端实现步骤: 创建一个客户端对象Socket,构造方法中绑定服务器的IP地址 和 端口号 使用Socket对 ...

  3. JN_0002:Win10禁止U盘拷贝文件的方法

    1,在电脑桌面使用快捷键win键+r唤出运行窗口,在搜索框中输入gpedit.msc,然后点击确定. 2,打开的本地组策略编辑器中依次点击展开计算机配置—管理模块—系统,在系统下找到并选中可移动存储访 ...

  4. 第六节:反射(几种写法、好处和弊端、利用反射实现IOC)

    一. 加载dll,读取相关信息 1. 加载程序集的三种方式 调用Assembly类下的三个方法:Load.LoadFile.LoadFrom. //1.1 Load方法:动态默认加载当前路径下的(bi ...

  5. Iterate over slices of a string

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

  6. CF611D lcp+dp

    本篇博客只是留个辣鸡的自己标记一下,误入的同学请出门左转博客 https://blog.csdn.net/loy_184548/article/details/50865777 代码神马的也是复制啊 ...

  7. Vue-cli 模拟数据库

    vue-cli2.x 版本开发: 新版在build目录下的webpack.dev.conf.js配置本地数据访问: 1,在const portfinder = require(‘portfinder’ ...

  8. Thread和Runnable的区别

    Runnable源码 Thread源码 结论 Thread实现了Runnable接口的类,使得run支持多线程. 因类的单一继承原则,推荐使用Runnable接口实现多线程

  9. centos 6 部署Nodejs

    线上环境需要一套nodjs,没话说,那就部署唠. 一.下载编译包.解压.软链 nodjs历史版本连接:https://nodejs.org/zh-cn/download/releases/ cd /u ...

  10. 20175226 2018-2019-2 《Java程序设计》第二周学习总结

    20175226 2018-2019-2 <Java程序设计>第二周学习总结 教材学习内容总结 基本数据类型与数组 标识符与关键字 标识符不能是关键字.true.false.null.且第 ...