思路:

状态压缩dp。需要一点优化,否则容易超时。

实现:

 #include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
using namespace std;
vector<int> G[];
int n, m, dp[ << ];
int main()
{
int p, x;
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)
{
scanf("%d", &p);
for (int j = ; j < p; j++)
{
scanf("%d", &x);
G[i].push_back(x);
}
}
dp[] = ;
for (int i = ; i < n; i++)
{
for (int j = ( << m + ) - ; j >= ; j--)
{
if (__builtin_popcount(j) != i) continue;
for (int k = ; k < G[i + ].size(); k++)
{
int tmp = G[i + ][k];
if (!(j >> tmp & )) dp[j | << tmp] += dp[j];
}
}
}
int cnt = ;
for (int j = ; j < ( << m + ) - ; j++)
if (__builtin_popcount(j) == n) cnt += dp[j];
printf("%d\n", cnt);
return ;
}

poj2441 Arrange the Bulls的更多相关文章

  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)

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

  3. POJ 2441 Arrange the Bulls 状压dp

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

  4. poj 2441 Arrange the Bulls

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

  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. Arrange the Bulls

    题目链接 #include <stdio.h> #include <algorithm> #include <string.h> #include <iost ...

随机推荐

  1. SQL Server 2012 安装图解教程(附sql2012下载地址)

    在安装微软最新数据库SQL Server 2012之前,编者先确定一下安装环境:Windonws 7 SP1,32位操作系统.CPU是2.1GHz赛扬双核T3500,内存2.93GB. sql2012 ...

  2. caioj1462: 【EXKMP】回文串

    不得不说这是一道好题(前排膜拜灯教授),其实这道题如果不说是EXKMP,很容易就想到Manacher(好像也可以这样做) 回到这道题,这样只有一个字符串,还要求回文?立刻想到了将这个串和它的反串跑EX ...

  3. hdu 超级楼梯 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2041 哦--对了,这些题读者可以直接忽略,我只是想练习一下自己薄弱的地方...... 题目意思我就不说 ...

  4. codeforces 440B. Balancer 解题报告

    题目链接:http://codeforces.com/problemset/problem/440/B 题目意思:给出 n 个数,求出这 n 个数的平均值avg,问对于这 n 个数里面中的每一个数,要 ...

  5. JQuery验证成功之后,使用ajax提交数据

    function checkForm(){ validator = $("#commentForm").validate({// #formId为需要进行验证的表单ID error ...

  6. python split space

    发现自己写python的空格split还挺多坎的,尤其是最后一个是空格的情形: def split(s): i = 0 ans = [] while i < len(s): start = i ...

  7. 隐马尔科夫模型HMM

    崔晓源 翻译 我们通常都习惯寻找一个事物在一段时间里的变化规律.在很多领域我们都希望找到这个规律,比如计算机中的指令顺序,句子中的词顺序和语音中的词顺序等等.一个最适用的例子就是天气的预测. 首先,本 ...

  8. 从OutStreamWriter 和Filewriter谈Java编码

    首先看JAVA API的描述: ABOUT OutputStreamWriter: "An OutputStreamWriter is a bridge from character str ...

  9. BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP

    BZOJ_2097_[Usaco2010 Dec]Exercise 奶牛健美操_二分答案+树形DP Description Farmer John为了保持奶牛们的健康,让可怜的奶牛们不停在牧场之间 的 ...

  10. 【Codeforces 757B】 Bash's big day

    [题目链接] 点击打开链接 [算法] 若gcd(s1,s2,s3....sk) > 1, 则说明 : 一定存在一个整数d满足d|s1,d|s2,d|s3....,d|sk 因为我们要使|s|尽可 ...