poj 2441 Arrange the Bulls (状压dp)
来源:互联网 发布:马尔可夫链 转化矩阵 编辑:程序博客网 时间:2024/05/23 00:08
在续挑战这本书,看了下状压但是不是很懂,因为老感觉他那几重循环有好多地方是有问题的,但是也不太清楚.
这一题是练习题第一题,然后我想了两个小时才出来,然后发现时间是人家十倍,空间是两倍,就很难过了.
大概我的思维是独一份的把,独一份的蠢..
dp[s][time] 在上一次time(滚动数组)之后,分配方式为s的方法有多少种.
/* xzppp */#include <iostream>#include <vector>#include <cstdio>using namespace std;#define FFF freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);#define lson MAXN,m,rt<<1#define rson m+1,r,rt<<1|1#define MP make_pair#define PB push_backtypedef long long ll;typedef unsigned long long ULL;const int MAXN = 20;const int MAXM = 20;const int INF = 0x7fffffff;const int MOD = 1e9+7;int dp[1<<MAXN][2];vector<int > G[MAXN+17];int main(int argc, char const *argv[]){ //FFF int n,m; scanf("%d%d",&n,&m); for (int i = 0; i < n; ++i) { int p; scanf("%d",&p); for (int j = 0; j < p; ++j) { int temp; scanf("%d",&temp); temp--; G[i].PB(temp); } } int ans = 0; for (int i = 0; i < G[0].size(); ++i) dp[1<<G[0][i]][0] = 1; int now = 0,last = 1; for (int i = 1; i < n; ++i) { swap(now,last); for (int s = (1<<m)-1; s > -1; --s) dp[s][now] = 0; for (int j = 0; j < G[i].size(); ++j) for (int s = (1<<m)-1; s > -1; --s) if(!((s>>G[i][j])&1)&&dp[s][last]>0) { dp[s|(1<<G[i][j])][now] += dp[s][last]; if(i==n-1) ans+=dp[s][last]; } } printf("%d\n",ans); return 0;}
阅读全文
0 0
- poj 2441 Arrange the Bulls(状压DP)
- poj 2441 Arrange the Bulls (状压dp)
- POJ--2441--Arrange the Bulls--状压DP-滚动数组优化
- poj 2441 Arrange the Bulls(状压DP入门)
- poj 2441 Arrange the Bulls 状压dp入门
- poj 2441 Arrange the Bulls(状压dp)
- 文章标题 POJ 2441 :Arrange the Bulls(状压DP)
- POJ 2441 Arrange the Bulls
- poj 2441 Arrange the Bulls
- POJ-2441-Arrange the Bulls
- POJ 2441 Arrange the Bulls
- POJ 2441 Arrange the Bulls
- POJ 2441 Arrange the Bulls
- poj 2441 Arrange the Bulls
- poj 2441Arrange the Bulls解题报告-状态压缩dp
- POJ 2441 Arrange the Bulls / 状态压缩DP
- POJ 2441 Arrange the Bulls 状态压缩DP
- POJ 2441 Arrange the Bulls(状态压缩DP)
- 欧拉回路
- STL-queue实现队列
- Visual Studio中C++关于Unicode字符集和多字节字符集
- ie6兼容问题
- 微信分享 errorCode 为-6
- poj 2441 Arrange the Bulls (状压dp)
- 《华为机试在线训练》之汽水瓶
- HDFS知识点总结
- hdu6154 CaoHaha's staff 找规律
- hdu 6143(精妙的递推)
- uC/OS-II系统学习笔记(5)—— uC/OS-II概述下篇
- 如何重写PictureBox的OnPaint方法绘制矩形,并实现拖动,鼠标悬停时提示拖拽方向
- Docker阿里加速器
- Java集合类