POJ 2411 Mondriaan's Dream
2014-03-05 17:39
134 查看
状态压缩dp。搜了n多题解。。。都看不懂- -!最后在波神的解释下将discuss里一超短神解理解了。。。不能更神。详细注释下。代码完全是抄的。
#include <cstdio> #include <algorithm> #include <cstring> #include <cstdlib> #include <iostream> #include <cmath> using namespace std; typedef long long LL; #define INF 1000000007 #define N 1000 int h, w; LL p; LL dp[13][1 << 12]; void dfs(int i, int s, int pos){当前行, 前一行状态, 当前列位置 if(pos == w){dp[i][s] += p;return ;}//结束时将当前行s状态加上前一行转移过来的状态数 dfs(i, s, pos + 1);//若当前位置(为0)不放直接跳过,若竖直放置(为1)则已经处理过直接跳过 if(pos <= w - 2 && !(s & (1 << pos)) && !(s & (1 << pos + 1)))dfs(i, s | (1 << pos) | (1 << pos + 1), pos + 2);//水平放置 } int main(){ while(scanf("%d%d", &h, &w), h || w){ memset(dp, 0, sizeof(dp)); p = 1; dfs(1, 0, 0); for(int i = 2; i <= h; i++){ for(int j = 0; j < (1 << w); j++){ if(dp[i - 1][j])p = dp[i - 1][j]; else continue; dfs(i, ~j & ((1 << w) - 1), 0);//将前一行状态置反,即前一行没放的位置当前行状态直接处理为1 } } printf("%I64d\n", dp[h][(1 << w) - 1]); } return 0; }
相关文章推荐
- poj 2411 Mondriaan's Dream 【状压dp】
- POJ 2411 Mondriaan's Dream (状压+dfs)
- POJ 2411
- POJ 2411 Mondriaan's Dream (状压DP)
- POJ 2411 Mondriaan's Dream(DP---状态压缩)
- POJ-2411 Mondriaan's Dream 状态压缩+动态规划
- POJ 2411 插头DP
- POJ 2411 (动态规划-状压DP AND 轮廓线DP)
- poj2411 Mondriaan's Dream(轮廓线dp)
- POJ_2411_Mondriaan's Dream
- poj2411——Mondriaan's Dream(状态压缩DP)
- POJ 2411 Mondriaan's Dream
- POJ 2411 Mondriaan's Dream 插头dp
- Mondriaan's Dream POJ - 2411 状压DP
- poj 2411 状态压缩dp
- L - Mondriaan's Dream POJ - 2411
- Mondriaan's Dream - POJ 2411(状态压缩)
- poj2411
- poj 2411 Mondriaan's Dream
- 状压dp poj2411 Mondriaan's Dream POJ - 2411