问题描述:
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.
Input
The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.
Output
For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.
Sample Input
1 2 1 3 1 4 2 2 2 3 2 4 2 11 4 11 0 0Sample Output
1 0 1 2 3 5 144 51205题目题意:给我们一个h*w的矩形,我们用1*2的矩形去覆盖,覆盖种数
状压DP:对于每一行我们用01二进制表示其状态1表示横放或者竖放的下面一块,0表示竖放的上面一块。
则上一行为0的地方这一行必须为1,其他的任意,还有一点上下俩行想与必须满足每一个连续的1区间的长度是偶数
很简单,只有上下为1才有是相与为1,那么都是横放,砖的长度为2偶数
代码如下:
#include
#include
#include
#include
#define ll long long
using namespace std;
ll dp[2][1<<12];
bool vis[1<<12];
int h,w;
bool check(int s)
{
int cnt = 0;
while(s){
if(s&1){
cnt++;
}
else{
if(cnt&1)return false;
cnt = 0;
}
s>>=1;
}
if(cnt&1)return false;
return true;
}
void init()
{
memset (vis,false,sizeof (vis));
for (int i=0;i<=(1<<11);i++){
if (check(i)) vis[i]=true;
}
}
int main()
{
init();
while (scanf("%d%d",&h,&w)!=EOF) {
if (h==0&&w==0) break;
memset (dp,0,sizeof (dp));
for (int i=0;i<(1<
先看一下大佬博客点击打开链接
从一个轮廓线转移到另一轮廓线要保证处理的当前结点的上方一定要被覆盖
#include
#include
#include
#include
using namespace std;
const double PI=acos(-1);
const int MAX=1e6+100;
const int MOD=1e9+7;
typedef long long ll;
ll d[2][1<<12];
int main()
{
int n,m;
while(scanf("%d%d",&n,&m)!=EOF)
{
if(n==0&&m==0)break;
memset(d,0,sizeof d);
int pre=0,now=1;
d[pre][(1<