您的位置:首页 > 其它

POJ2411 Mondriaan's Dream

2017-09-11 15:03 176 查看
Mondriaan's Dream

Time Limit: 3000MSMemory Limit: 65536K
Total Submissions: 17769Accepted: 10198
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.

#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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: