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 ...
随机推荐
- 图形绘制处理逻辑VC
// 逻辑1:先从资源中读取背景资源,然后将绘图对象与DC绑定,通过绘图对象绘出背景 // 逻辑2:先从资源中读取背景资源,新建一个MEMDC,将绘图对象与MEMDC绑定,并且 // 通过绘图对象在内 ...
- BZOJ 1529 [POI2005]ska Piggy banks:并查集
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1529 题意: Byteazar有N个小猪存钱罐. 每个存钱罐只能用钥匙打开或者砸开. By ...
- Linux下查看端口占用情况
用启动服务的账号登录,然后运行命令: lsof -i:<端口号> 也可使用命令: netstat -apn|grep <端口号> 找到进程号以后,再使用以下命令查看详细信息: ...
- 写个sleep玩玩
static void sig_when_weakup(int no){ printf("weakup weakup\n"); longjmp(buf, ); } void wea ...
- linux 进程学习笔记-named pipe (FIFO)命名管道
与“无名管道”不同的是,FIFO拥有一个名称来标志它,所谓的名称实际上就是一个路径,比如“/tmp/my_fifo”,其对应到磁盘上的一个管道文件,如果我们用file命令来查看其文件类型的话,会得到如 ...
- PHP留言小练习
实现功能: 留言.搜索.编辑.删除.详情页.时间.点击量 页面划分: index.html(留言列表页) add.html(留言页) edit.php(编辑页) del.php(删除页) view.p ...
- 'QObject& QObject::operator=(const QObject&)' is private——无法将自定义的QObject子类放入Qt容器(container)中
先贴出问题的代码: #include<QCoreApplication> classMyObject:publicQObject { public: MyObject(QObject*pa ...
- 「LuoguP3389」【模板】高斯消元法
题目背景 Gauss消元 题目描述 给定一个线性方程组,对其求解 输入输出格式 输入格式: 第一行,一个正整数 nn 第二至 n+1n+1行,每行 n+1n+1 个整数,为a_1, a_2 \cdot ...
- lsnrctl启动报错,Linux Error: 29: Illegal seek
[oracle@phydb admin]$ lsnrctl startLSNRCTL for Linux: Version 11.2.0.1.0 - Production on 15-SEP-2014 ...
- IoT:template
ylbtech-IoT: 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 6.返回顶部 作者:ylbtech出处:http://ylbtech.cnb ...