Arrange the Bulls
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <iostream>
using namespace std;
typedef long long ll; inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
} /********************************************************************/ const int maxn = ;
int n, m;
int dp[(<<)+];
int ok[maxn][maxn]; void solve(){
dp[] = ;
for(int i = ;i <= n;i++){
for(int j = (<<m);j >= ;j--){
if(dp[j]){ //j状态有i-1头牛
for(int k = ;k <= m;k++){ //每一个牛棚
if(ok[i][k] && (j != (j|(<<(k-)))))
dp[j|(<<(k-))] += dp[j];
}
}
dp[j] = ;
}
}
int ans = ;
for(int i = ;i < (<<m);i++){
ans += dp[i];
}
printf("%d\n", ans);
return;
} int main(){
while(~scanf("%d%d", &n ,&m)){
memset(ok, , sizeof(ok));
memset(dp, , sizeof(dp)); for(int i = ;i <= n;i++){
int a, b;
a = read();
while(a--){
b = read();
ok[i][b] = ;
}
}
solve();
}
return ;
}
Arrange the Bulls的更多相关文章
- poj 2441 Arrange the Bulls(状态压缩dp)
Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...
- POJ 2441 Arrange the Bulls 状压dp
题目链接: http://poj.org/problem?id=2441 Arrange the Bulls Time Limit: 4000MSMemory Limit: 65536K 问题描述 F ...
- poj 2441 Arrange the Bulls
Arrange the Bulls Time Limit: 4000MS Memory Limit: 65536K Total Submissions: 5427 Accepted: 2069 ...
- POJ2441 Arrange the Bulls(状压DP)
题目是,有n头牛,每头牛都喜爱某几个草地,要把这n头牛分配给m个不同的它们喜爱的草地,问有几种分配方式. dp[n][S]表示前n头牛分配完毕后占用的草地集合是S的方案数 dp[0][0]=1 dp[ ...
- Arrange the Bulls [POJ2441] [状压DP]
题意 n头牛,m个房间,每头牛有自己喜欢的房间,问每头牛都住进自己喜欢的房间有多少种分配方法? Input In the first line of input contains two intege ...
- POJ 2441 Arrange the Bulls 状态压缩递推简单题 (状态压缩DP)
推荐网址,下面是别人的解题报告: http://www.cnblogs.com/chasetheexcellence/archive/2012/04/16/poj2441.html 里面有状态压缩论文 ...
- POJ 2441 Arrange the Bulls(状态压缩DP)
题意很简单,n头牛,m个位置,每头牛有各自喜欢的位置,问安排这n头牛使得每头牛都在各自喜欢的位置有几种安排方法. 2000MS代码: #include <cstdio> #include ...
- POJ 2441 Arrange the Bulls(状压DP)
[题目链接] http://poj.org/problem?id=2441 [题目大意] 每个人有过个喜欢的篮球场地,但是一个场地只能给一个人, 问所有人都有自己喜欢的场地的方案数. [题解] 状态S ...
- poj2441 Arrange the Bulls
思路: 状态压缩dp.需要一点优化,否则容易超时. 实现: #include <cstdio> #include <vector> #include <cstring&g ...
随机推荐
- Android蓝牙通讯【转】
本文转载自:http://blog.csdn.net/vnanyesheshou/article/details/51554852 随着可穿戴设备的流行,研究蓝牙是必不可少的一门技术了. 总结了下蓝牙 ...
- 在datax之前版本中添加filewriter并创建job时出现问题
问题描述:
- eclipse批量修改package、import中的包名
问题:想把以前开发的包,用到新项目中,怎么操作呢? 解决方案: 把文件夹复制到新项目包中,同时需要更改很多package.import中的包名第一步:打开一个java文件,选中要替换的字段: 第二步: ...
- JAVA-关键字&标识符
关键字: 关键字就是在java程序中具备特殊含义的标识符.关键字一般用于描述一个程序的结构或者表示数据类型.他们用来表示一种数据类型,或者表示程序的结构等,关键字不能用作变量名.方法名.类名.包名. ...
- HDU 2643 Rank:第二类Stirling数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2643 题意: 有n个个选手参赛,问排名有多少种情况(可以并列). 题解: 简化问题: 将n个不同的元素 ...
- OpenCV——花环生成函数
// define head function #ifndef PS_ALGORITHM_H_INCLUDED #define PS_ALGORITHM_H_INCLUDED #include < ...
- linux增加vlan网卡配置
1.编辑文件/etc/sysconfig/network在里面添加一行:VLAN=yes2.再生成网卡设备的配置文件ifcfg-eth1.10和ifcfg-eth1.240cd /etc/syscon ...
- BZOJ_3744_Gty的妹子序列
BZOJ3744: Gty的妹子序列 https://lydsy.com/JudgeOnline/problem.php?id=3744 分析: 预处理出来每一块块首到所有位置的逆序对数. 查询时主席 ...
- ACM学习历程—FZU 2144 Shooting Game(计算几何 && 贪心 && 排序)
Description Fat brother and Maze are playing a kind of special (hentai) game in the playground. (May ...
- WPF开发学习笔记(转)
总结下学习WPF的笔记,方便查阅 1 编译 添加程序集引用:WindowsBase.dll,PresentationCore.dll,PresentationFramework.dll 2 布局 ...