poj2441 Arrange the Bulls
思路:
状态压缩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的更多相关文章
- POJ2441 Arrange the Bulls(状压DP)
题目是,有n头牛,每头牛都喜爱某几个草地,要把这n头牛分配给m个不同的它们喜爱的草地,问有几种分配方式. dp[n][S]表示前n头牛分配完毕后占用的草地集合是S的方案数 dp[0][0]=1 dp[ ...
- 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 ...
- 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 ...
- Arrange the Bulls
题目链接 #include <stdio.h> #include <algorithm> #include <string.h> #include <iost ...
随机推荐
- bootstrap学习心得
一.html的编写规范 <!DOCTYPE html> <html lang="zh-CN"> <head> <title>Page ...
- 构造方法,重载,static,math类(java基础知识七)
1.构造方法概述和格式 * A:构造方法概述和作用 * 给对象的数据(属性)进行初始化 * B:构造方法格式特点 * a:方法名与类名相同(大小也要与类名一致) * b:没有返 ...
- Oracle:impdb导入
最近有现场给我一份用expdp导出dmp文件,我用imp导入时,报错.因为导出dmp的数据库是11g,导入的数据库也是11g, 但客户端安装的是10g,不能用imp导入:所以只能试着用impdp导入: ...
- 「HNSDFZ暑期集训 测试1」「LuoguT36488」 连连看
题目描述 给定一个n × m的矩形地图,每个各自上可能为空,可能有牌,牌上有一个数字. 对于两张同样数字的牌,如果我们可以在地图上用不超过三根水平或竖直,在地图界内,且不经过其他牌的线段将两张牌连起来 ...
- python之路,day6-面向对象
一.面向过程编程 简单的说就是:如果你只是写一些简单的脚本,去做一些一次性任务,用面向过程的方式是极好的,但是如果你要处理的任务比较复杂,且需要不断迭代和维护的,那还是用面向对象最方便了. 二.面向对 ...
- 【旧文章搬运】更正一个枚举PspCidTable时的错误
原文发表于百度空间及看雪论坛,2009-02-27 看雪论坛地址:https://bbs.pediy.com/thread-82919.htm============================= ...
- js 模拟a标签打开新网页
在这里备份一下,方便以后查找. var el = document.createElement("a"); document.body.appendChild(el); e ...
- 容器之vector
#include <iostream> #include <vector> #include <string.h> #include <algorithm&g ...
- opencord视频截图
参考:https://www.youtube.com/watch?v=Teu9jK6GF6s
- linux软硬连接学习总结
创建连接实质上就是给系统中已经存在的文件指定另外一个可以访问它的名称,linux系统当中连接的创建有两种形式:硬链接(Hard Link),与符号链接(Symbloic Link)既软链接. ln命令 ...