POJ2411 Mondriaan's Dream
2017-09-11 15:03
176 查看
Mondriaan's Dream
Description
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.
POJ2411
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 17769 | Accepted: 10198 |
Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series' (where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways.
#include <iostream> #include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <algorithm> #define min(a, b) ((a) < (b) ? (a) : (b)) #define max(a, b) ((a) > (b) ? (a) : (b)) inline void read(long long &x) { x = 0;char ch = getchar(), c = ch; while(ch < '0' || ch > '9')c = ch, ch = getchar(); while(ch <= '9' && ch >= '0')x = x * 10 + ch - '0', ch = getchar(); if(c == '-')x = -x; } const long long INF = 0x3f3f3f3f; const long long MAXW = 15; const long long MAXH = 15; long long status[1 << MAXH][2], w, h, tot, dp[MAXW][1 << MAXH];//[0]代表pre,[1]代表now /* 状态定义: 0:不放 或者 竖着的上面一格 1:横着的 或者 竖着的下面一格 */ void dfs(long long pre, long long now, long long d) { if(d > h)return; if(d == h) { status[++tot][0] = pre; status[tot][1] = now; return; } dfs((pre << 2) | 3, (now << 2) | 3, d + 2); dfs(pre << 1, (now << 1) | 1, d + 1); dfs((pre << 1) | 1, now << 1, d + 1); } int main() { read(w), read(h); while(w + h) { tot = 0; dfs(0,0,0); memset(dp, 0, sizeof(dp)); dp[0][(1 << h) - 1] = 1; for(register long long i = 0;i < w;++ i) { for(register long long j = 1;j <= tot;++ j) dp[i + 1][status[j][1]] += dp[i][status[j][0]]; } printf("%lld\n", dp[w][(1 << h) - 1]); read(w), read(h); } return 0; }
POJ2411
相关文章推荐
- poj 2411 (状态压缩)
- poj 2411 状态压缩DP 铺砖块
- poj 2411 Mondriaan's Dream
- POJ-2411 Mondriaan's Dream(轮廓线dp)
- POJ-2411 Mondriaan's Dream 状态压缩+动态规划
- POJ 2411 && HDU 1400 Mondriaan's Dream(状态压缩DP)
- poj 2411
- poj 2411 状态压缩DP
- poj2411——Mondriaan's Dream(状态压缩DP)
- POJ 2411 解题报告
- poj2411 Mondriaan's Dream
- Poj 2411 铺砖问题
- 状态压缩动态规划 POJ 2411 (编程之美-瓷砖覆盖地板)
- poj 2411 Mondriaan's Dream(状态压缩DP)
- POJ 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream
- poj 2411 Mondriaan's Dream 轮廓线dp
- poj-2411 Mondriaan's Dream ***
- Mondriaan's Dream - POJ 2411 状压dp
- poj2411 Mondriaan's Dream【插头dp】