poj2441 Arrange the Bulls】的更多相关文章

题目是,有n头牛,每头牛都喜爱某几个草地,要把这n头牛分配给m个不同的它们喜爱的草地,问有几种分配方式. dp[n][S]表示前n头牛分配完毕后占用的草地集合是S的方案数 dp[0][0]=1 dp[n][S]+=dp[n-1][S-x](x∈S且n喜爱x) 不过的状态这样空间开销太大了,事实上n这个维度的信息S就包含了,所以dp[S]即可. #include<cstdio> #include<cstring> #include<algorithm> using nam…
思路: 状态压缩dp.需要一点优化,否则容易超时. 实现: #include <cstdio> #include <vector> #include <cstring> #include <iostream> using namespace std; vector<]; << ]; int main() { int p, x; scanf("%d%d", &n, &m); ; i <= n; i++…
Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to play basketball with the other bulls because they believe that the others are all very weak. Farmer Johnson has N cows (we number the cows from 1 to…
题目链接: http://poj.org/problem?id=2441 Arrange the Bulls Time Limit: 4000MSMemory Limit: 65536K 问题描述 Farmer Johnson's Bulls love playing basketball very much. But none of them would like to play basketball with the other bulls because they believe that…
Arrange the Bulls Time Limit: 4000MS   Memory Limit: 65536K Total Submissions: 5427   Accepted: 2069 Description Farmer Johnson's Bulls love playing basketball very much. But none of them would like to play basketball with the other bulls because the…
题意 n头牛,m个房间,每头牛有自己喜欢的房间,问每头牛都住进自己喜欢的房间有多少种分配方法? Input In the first line of input contains two integers N and M (1 <= N <= 20, 1 <= M <= 20). Then come N lines. The i-th line first contains an integer P (1 <= P <= M) referring to the numb…
推荐网址,下面是别人的解题报告: http://www.cnblogs.com/chasetheexcellence/archive/2012/04/16/poj2441.html 里面有状态压缩论文的链接,可以看看. 该解题报告中用的是二维数组,但是很显然的是,递推式中的下一行只与上一行有关,类似于最长公共子序列,可以用滚动数组,在滚动数组后发现只用一个数组就可以了.至于是不是要和0-1背包一样得按从大到小的顺序,我没有,我的状态是从小到大的顺序,但是也AC了. 如果不用滚动数组,会超内存.…
题意很简单,n头牛,m个位置,每头牛有各自喜欢的位置,问安排这n头牛使得每头牛都在各自喜欢的位置有几种安排方法. 2000MS代码: #include <cstdio> #include <cstring> <<)+]; << ) + ]; //用来数出状态为i时1的个数,具体到这个题中就是 //状态为i时有多少头牛已经安排好牛棚 void CountOne(int m) { ; i< ( << m); ++i) { ; ; j< m…
[题目链接] http://poj.org/problem?id=2441 [题目大意] 每个人有过个喜欢的篮球场地,但是一个场地只能给一个人, 问所有人都有自己喜欢的场地的方案数. [题解] 状态S表示已经用了那些场地,顺序递推每个人满足需求的情况即可. [代码] #include <cstdio> #include <cstring> using namespace std; const int N=25; int n,m,u,x,dp[2][1<<20],a[N]…
题目链接 #include <stdio.h> #include <algorithm> #include <string.h> #include <iostream> using namespace std; typedef long long ll; inline int read() { ,f=;char ch=getchar(); ;ch=getchar();} +ch-';ch=getchar();} return x*f; } /********…