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 ...
随机推荐
- java中的泛型类和泛型方法
1.泛型是什么? 泛型(Generic type 或者 generics)是对 Java 语言的类型系统的一种扩展,以支持创建可以按类型进行参数化的类. 可以在集合框架(Collection fram ...
- 「NOIP2010」「LuoguP1514」引水入城
Description 在一个遥远的国度,一侧是风景秀美的湖泊,另一侧则是漫无边际的沙漠.该国的行政区划十分特殊,刚好构成一个 N×M 列的矩形,如上图所示,其中每个格子都代表一座城市,每座城市都有一 ...
- 【POJ 2407】 Relatives
[题目链接] 点击打开链接 [算法] 欧拉函数 [代码] #include <algorithm> #include <bitset> #include <cctype& ...
- Excel: 应用Match/Vlookup比较Excel两列的不同数据
假设Excel中有两列,现在要比较两列数据的不同.
- EF提高性能
实体框架 5 性能注意事项 作者:David Obando.Eric Dettinger 等 发布时间:2012 年 4 月 1.简介 对象关系映射框架是一种在面向对象的应用程序中提供数据访问抽象的便 ...
- Hibernate 4.3 配置文件实现
1.建立web项目 2.复制相关的jar文件到 项目的lib目录下antlr-2.7.7.jardom4j-1.6.1.jarhibernate-commons-annotations-4.0.5.F ...
- A. Meeting of Old Friends
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- centos7无故重启-内核升级
最近有一台物理服务器,centos7操作系统,无故重启,每天都会发生这种情况: 解决: 升级内核 CentOS 允许使用 ELRepo,这是一个第三方仓库,可以将内核升级到最新版本,使用ELRepo升 ...
- ASP.NET Core MVC 2.x 全面教程_ASP.NET Core MVC 01. 创建项目 +项目结构和配置简介
新建项目:Tutotial.Web 解决方案名称可以把web去掉 视频里面把git这个选项勾选了.我就不勾选了 dotnet CLI创建项目 首先必须安装好了.net Core的SDK dotnet ...
- 任务17:从UML角度来理解依赖
什么是依赖 如果我们用EF操作数据库. 那么CustomerController就对Context形成了依赖. 我们这种依赖的写法就是隐式的依赖 显式依赖于隐式依赖 怎么理解隐式的依赖呢? 三层架构是 ...