题目链接

 #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的更多相关文章

  1. poj 2441 Arrange the Bulls(状态压缩dp)

    Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to ...

  2. POJ 2441 Arrange the Bulls 状压dp

    题目链接: http://poj.org/problem?id=2441 Arrange the Bulls Time Limit: 4000MSMemory Limit: 65536K 问题描述 F ...

  3. poj 2441 Arrange the Bulls

    Arrange the Bulls Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 5427   Accepted: 2069 ...

  4. POJ2441 Arrange the Bulls(状压DP)

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

  5. Arrange the Bulls [POJ2441] [状压DP]

    题意 n头牛,m个房间,每头牛有自己喜欢的房间,问每头牛都住进自己喜欢的房间有多少种分配方法? Input In the first line of input contains two intege ...

  6. POJ 2441 Arrange the Bulls 状态压缩递推简单题 (状态压缩DP)

    推荐网址,下面是别人的解题报告: http://www.cnblogs.com/chasetheexcellence/archive/2012/04/16/poj2441.html 里面有状态压缩论文 ...

  7. POJ 2441 Arrange the Bulls(状态压缩DP)

    题意很简单,n头牛,m个位置,每头牛有各自喜欢的位置,问安排这n头牛使得每头牛都在各自喜欢的位置有几种安排方法. 2000MS代码: #include <cstdio> #include ...

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

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

  9. poj2441 Arrange the Bulls

    思路: 状态压缩dp.需要一点优化,否则容易超时. 实现: #include <cstdio> #include <vector> #include <cstring&g ...

随机推荐

  1. 《avascript 高级程序设计(第三版)》 ---第三章 基本概念

    本章主要介绍Javasript语言的一些语法: 1.严格模式:开启:"use strict"; 2.变量:全部用var来定义,在函数中使用的称为局部变量,不能全局使用. 3.数据类 ...

  2. 《CSS权威指南(第三版)》---第三章 结构和层叠

    这章主要讲的是当某个对象被选择器多次提取使用样式之后的一些冲突性解决方案: 1.特殊性:指的是当多个效果作用的时候的最终选择: 这个规则用0,0,0,0来比较.其中:内联式是1,0,0,0  ID选择 ...

  3. ES6 Class基本用法

    JavaScript 语言中,生成实例对象的传统方法是通过构造函数.下面是一个例子. function Point(x, y) { this.x = x; this.y = y; } Point.pr ...

  4. 使用C语言解析URL

    1. [代码]容易写成自己输入URL,这里测试一个例子     #include <stdio.h>#include <stdlib.h>#include <string ...

  5. 设置document.domain实现js跨域注意点

    转自:http://www.cnblogs.com/fsjohnhuang/archive/2011/12/07/2279554.html document.domain 用来得到当前网页的域名.比如 ...

  6. redis持久化的方式RDB 和 AOF

    redis持久化的方式RDB 和 AOF 一.对Redis持久化的探讨与理解 目前Redis持久化的方式有两种: RDB 和 AOF 首先,我们应该明确持久化的数据有什么用,答案是用于重启后的数据恢复 ...

  7. L92

    The Difference between Honesty and Cheating We sign our names to various documents all the time. Som ...

  8. java-05 面向对象

    class StudentDemo { String name; int age; String address; public void study(){ System.out.println(&q ...

  9. 更换mysql数据目录后出现 ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 的解决办法

    服务器上的mysql默认数据目录为/var/lib/mysql/,同时服务器的/空间不是很大,而近期又有大量的日志需要导入进行分析,时常搞得/的空间捉襟见肘,晚上一狠心就想把mysql的数据目录转移到 ...

  10. python使用uuid生成唯一id或str

    介绍: UUID是128位的全局唯一标识符,通常由32字节的字符串表示. 使用: import uuid print uuid.uuid1() 14bfe806-f1c7-11e6-83b5-0680 ...