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"表示),只有 ...
随机推荐
- Oracle 的闪回技术 --flashback
SQL Fundamentals: 表的创建和管理 如何开启数据库闪回? SQL> shutdown immediate; ORA-01109: database not open Databa ...
- Linux服务器报错too many open files错误解决方案
1.本质解决方案按照oracle的安装脚本中以下几项文件进行相应配置: cp /etc/security/limits.conf /etc/security/limits.conf.bak echo ...
- android(十四)四种启动模式
standard 启动的activity会每次都重新创建一个activity放到任务栈中.这是系统默认的启动模式. singleTop启动的activity,如果任务的栈顶刚好存在当前的activit ...
- 【Python】两个for循环嵌套练习
要求:取下方篮框中内容并写入csv文件中.用两个for循环将每一行取出来作为一个元素存放到新数组中. # coding=utf-8 from selenium import webdriver fro ...
- jquery序列化表单以及回调函数的使用
在开发项目中.将前台的值传给后台,有时的JSP表单中的值有一两个,也有所有的值,假设这时一个个传,必然不是非常好的办法,所以使用jQuery提供的表单序列化方法,能够非常好的解决问题.同一时候能够封装 ...
- 使用spring boot ,和前端thymeleaf模板进行开发路径问题
加入引用:<html xmlns:th="http://www.thymeleaf.org">1:引用templates模板下面的文件时,不要用/绝对路径. 2:引用s ...
- 6.2 Controllers -- Representing Multipe Models
1. 一个controller的model可以代表几个记录也可以代表单个.这里,路由的model hook返回一个歌曲数组: app/routes/songs.js export default Em ...
- SecureCRT 会话空闲时超时退出处理
参考文章:http://www.cnblogs.com/xuxm2007/archive/2011/04/21/2023611.html http://yunwei.blog.51cto.com/38 ...
- Fiddler 手机无法上网问题
一.Fiddler版本升级后需要升级netframework 二.每一个域名点击需要授权 出现此页面依次点击显示详细信息和访问此网站. 有时候网站白板,可能是cdn域名没有授权的原因,可以直接在url ...
- postman--实现接口自动化测试
postman使用 开发中经常用postman来测试接口,一个简单的注册接口用postman测试: 接口正常工作只是最基本的要求,经常要评估接口性能,进行压力测试. postman进行简单压力测试 下 ...