POJ 2411 状压DP经典
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 16771 | Accepted: 9683 |
Description

Expert as he was in this material, he saw at a glance that he'll
need a computer to calculate the number of ways to fill the large
rectangle whose dimensions were integer values, as well. Help him, so
that his dream won't turn into a nightmare!
Input
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
Foreach 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 0
Sample Output
1
0
1
2
3
5
144
51205
Source
#include<cstring>
#include<cstdio>
using namespace std;
#define LL long long
LL dp[2][2050];
LL ans[15][15];
bool check(int x,int i)
{ return x&(1<<i); }
bool comp(int A,int B,int N)
{
int i=0,j,k;
while(i<N){
if(!check(A,i)){
if(!check(B,i)) return 0;
i++;
}
else{
if(!check(B,i)) i++;
else {
if(i==N-1||!check(A,i+1)||!(check(A,i+1)&&check(B,i+1))) return 0;
else i+=2;
}
}
}
return 1;
}
void solve(int N,int M)
{
if(ans[N][M]+1) {printf("%lld\n",ans[N][M]);return;}
memset(dp,0,sizeof(dp));
dp[0][(1<<N)-1]=1;
int cur=1;
for(int i=1;i<=M;++i){
for(int j=0;j<(1<<N);++j){dp[cur][j]=0;
for(int k=0;k<(1<<N);++k){
if(comp(j,k,N)) dp[cur][j]+=dp[cur^1][k];
}
}
cur^=1;
}
ans[N][M]=ans[M][N]=dp[cur^1][(1<<N)-1];
printf("%lld\n",dp[cur^1][(1<<N)-1]);
}
int main()
{
memset(ans,-1,sizeof(ans));
int N,M,i,j,k,l;
while(scanf("%d%d",&N,&M)!=EOF&&(N||M)){
if(N*M%2==1) {puts("0");continue;}
if(N>M) {swap(N,M);}
solve(N,M); //M行N列
}
return 0;
}
POJ 2411 状压DP经典的更多相关文章
- POJ 2411 状压dp
F - Mondriaan's Dream Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I6 ...
- POJ 3254 (状压DP) Corn Fields
基础的状压DP,因为是将状态压缩到一个整数中,所以会涉及到很多比较巧妙的位运算. 我们可以先把输入中每行的01压缩成一个整数. 判断一个状态是否有相邻1: 如果 x & (x << ...
- poj 1170状压dp
题目链接:https://vjudge.net/problem/POJ-1170 题意:输入n,表示有那种物品,接下来n行,每行a,b,c三个变量,a表示物品种类,b是物品数量,c代表物品的单价.接下 ...
- [NOI2001] 炮兵阵地 (状压Dp经典例题)
如果您的电脑比较优秀能在 1sec 内跑过 2^1000 的时间复杂度,不妨你可以尝试一下,其实实际时间复杂度远远少于 2^1000,作为骗分不错的选择QAQ,然后我们来分析一下正解: 很显然此题是一 ...
- POJ 3254 状压DP
题目大意: 一个农民有一片n行m列 的农场 n和m 范围[1,12] 对于每一块土地 ,1代表可以种地,0代表不能种. 因为农夫要种草喂牛,牛吃草不能挨着,所以农夫种菜的每一块都不能有公共边. ...
- poj 1185(状压dp)
题目链接:http://poj.org/problem?id=1185 思路:状态压缩经典题目,dp[i][j][k]表示第i行状态为j,(i-1)行状态为k时最多可以放置的士兵个数,于是我们可以得到 ...
- poj 3254 状压dp入门题
1.poj 3254 Corn Fields 状态压缩dp入门题 2.总结:二进制实在巧妙,以前从来没想过可以这样用. 题意:n行m列,1表示肥沃,0表示贫瘠,把牛放在肥沃处,要求所有牛不能相 ...
- poj 3311 状压DP
经典TSP变形 学到:1.floyd O(n^3)处理随意两点的最短路 2.集合的位表示,我会在最后的总结出写出.注意写代码之前一定设计好位的状态.本题中,第0位到第n位分别代表第i个城市,1是已经 ...
- 二维状压DP经典题
炮兵阵地 题目链接 题目大意:在n*m的地图上放置炮兵,每个炮兵的攻击范围是上下左右两格内,有两种不同的地形,山地(用"H" 表示),平原(用"P"表示),只有 ...
随机推荐
- python安装whl文件的注意事项(windows系统)
首先给大家来一波福利,在没有连接外网(互联网)的情况下,只有公司内网或者断网情况下,需要安装python的一些依赖,不会操作的同学可能就会遇到麻烦.这里教大家离线安装python依赖. 方法:使用.w ...
- Python开发【Django】:CMDB基础
浅谈ITIL TIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central ...
- Keras常用层
Dense层:全连接层 Activatiion层:激活层,对一个层的输出施加激活函数 Dropout层:为输入数据施加Dropout.Dropout将在训练过程中每次更新参数时按一定概率(rate)随 ...
- HTML---初识HTML
版权声明:本文为博主原创文章.不经博主同意注明链接就可以转载. https://blog.csdn.net/Senior_lee/article/details/33723573 H ...
- python基础之员工信息表作业
周末大礼包 文件存储格式如下: id, name, age, phone, job 1, Alex, 22, 13651054608, IT 2, Egon, 23, 13304320533, Tea ...
- vue基础篇(一)
1.简介 Vue (读音 /vjuː/,类似于 view) 是一套用于构建用户界面的渐进式框架.与其它大型框架不同的是,Vue 被设计为可以自底向上逐层应用.Vue 的核心库只关注视图层,不仅易于上手 ...
- Entity Framework在WCF中序列化的问题(转)
问题描述 如果你在WCF中用Entity Framework来获取数据并返回实体对象,那么对下面的错误一定不陌生. 接收对 http://localhost:5115/ReService.svc 的 ...
- ts 绘制多边形
let bg = this.createBitmapByName("123_png"); this.addChild(bg) bg.x = this.stage.width / 2 ...
- Python 中的多维字典
Python中的dict可以实现迅速查找.那么有没有像数组有二维数组一样,有二维的字典呢?比如我需要对两个关键词进行查找的时候.2D dict 可以通过 dict_2d = {'a': {'a': 1 ...
- 【知识总结】Activiti工作流学习入门
1. 我理解的工作流: 在工作中慢慢接触的业务流程,就向流程控制语言一样,一步一步都对应的不同的业务,但整体串联起来就是一个完整的业务.而且实际工作中尤其是在企业内部系统的研发中,确实需要对应许多审批 ...