HDU 1400 Mondriaan's Dream

状压DP。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;

int h,w;
long long dp[15][(2<<12)+10];
bool flag[(2<<12)+10],c[(2<<11)+10];
int b[15];

void dfs(int p){
    if(p==w){
        int st=0;
        for(int i=0;i<w;i++) st=st+c[i]*b[i];
        flag[st]=1; return;
    }
    if(c[p]==1) dfs(p+1);
    else{
        if(p+1<w) {c[p]=1; c[p+1]=1;dfs(p+1);c[p]=0; c[p+1]=0;}
        dfs(p+1);
    }
}

int main()
{
    b[0]=1; for(int i=1;i<=11;i++) b[i]=2*b[i-1];
    while(~scanf("%d%d",&h,&w))
    {
        if(h==0&&w==0) break;
        dfs(0); memset(dp,0,sizeof dp);
        for(int i=0;i<=(1<<w)-1;i++) dp[0][i]=flag[i];
        for(int i=1;i<h;i++)
        {
            for(int j=0;j<=(1<<w)-1;j++)
            {
                if(dp[i-1][j]==0) continue;
                int st=j^((1<<w)-1);
                for(int k=0;k<=(1<<w)-1;k++)
                {
                    if((flag[k]==0)||((st&k)!=0)) continue;
                    dp[i][st|k]+=dp[i-1][j];
                }
            }
        }
        printf("%lld\n",dp[h-1][(1<<w)-1]);
    }
    return 0;
}

HDU 1400 Mondriaan's Dream

时间: 2024-12-18 22:53:33

HDU 1400 Mondriaan's Dream的相关文章

POJ 2411 &amp;&amp; HDU 1400 Mondriaan&#39;s Dream (状压dp 经典题)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12341   Accepted: 7204 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

[ACM] HDU 1400 Mondriaan&#39;s Dream (状态压缩,长2宽1长方形铺满)

Mondriaan's Dream Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 783    Accepted Submission(s): 506 Problem Description Squares and rectangles fascinated the famous Dutch painter Piet Mondri

[ACM] HDU 1400 Mondriaan&amp;#39;s Dream (状态压缩,长2宽1长方形铺满)

Mondriaan's Dream Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 783    Accepted Submission(s): 506 Problem Description Squares and rectangles fascinated the famous Dutch painter Piet Mondri

POJ2411(Mondriaan&#39;s Dream)

题目链接:传送门 题目大意:用1*2大小的砖块去铺满n*m大小的地面,有多少种方案 题目思路:因为1<=n,m<=11,并且砖块是1*2,故可以用二进制思想,也就是状态压缩DP,其中矩阵中为0的元素表示当前位置竖着放一块砖,而连着 两个1表示横着放一块砖(状态压缩真的很奇妙) #include <iostream> #include <cstdio> #include <cstdlib> #include <cmath> #include <

poj 2411 Mondriaan&#39;s Dream(状压DP)

Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 12232   Accepted: 7142 Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 'toilet series

POJ 2411 Mondriaan&#39;s Dream

题目链接:http://poj.org/problem?id=2411 状态压缩Dynamic Programming. For each row, at ith position, 1 means that there is a block placed at this row and next row (vertically). otherwise, its 0. For the example in question, the state of For the example in que

【poj2411】 Mondriaan&#39;s Dream

http://poj.org/problem?id=2411 (题目链接) 题意 一个$n*m$的网格,用$1*2$的方块填满有多少种方案. Solution 轮廓线dp板子.按格dp,对上方和左方的格子的占用情况进行讨论转移.0表示已放置,1表示未放置. 细节 LL,滚动清空数组. 代码 // poj2411 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring>

poj 2411 Mondriaan&#39;s Dream(状态压缩+dp)

 题意:用1*2砖块铺满n*m的房间. 思路转自:http://www.cnblogs.com/scau20110726/archive/2013/03/14/2960448.html 因为这道题输入范围在11*11之间,所以可以先打表直接输出.......... 状态压缩DP 经典覆盖问题,输入n和m表示一个n*m的矩形,用1*2的方块进行覆盖,不能重叠,不能越出矩形边界,问完全覆盖完整个矩形有多少种不同的方案 其中n和m均为奇数的话,矩形面积就是奇数,可知是不可能完全覆盖的.接着我们来看

POJ 2411 Mondriaan&#39;s Dream(状压DP)

http://poj.org/problem?id=2411 求一个n*m矩阵用1*2方块去填满的情况有几种 思路:状压dp,先预处理那些状态之间能互相到达,情况就几种,上一个两个1,下一个状态也两个1,上一个为0,下一个必须为1,还有一种是上一个为1,下一个为0的情况 然后就一层层往后递推即可 代码: #include <stdio.h> #include <string.h> #include <algorithm> using namespace std; int