poj 2411((多米诺骨牌问题))
| Time Limit: 3000MS | Memory Limit: 65536K | |
| Total Submissions: 12854 | Accepted: 7486 |
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
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 0
Sample Output
1
0
1
2
3
5
144
51205
题目描述:
之前做过用1*2的骨牌覆盖2*n的棋盘,考虑第一个骨牌的方法,要么两个横着放,要么一个竖着放,
如果是n*m的棋盘,那么它还是可以用2*n的棋盘(每两行)递推过去的,每行(包括第一行)有三种选择,横着放,竖着放,
不放,如果用1表示横着放和竖着放的第二个,0表示竖着放的第一个和不放,每次都是两行之间的转换,
找出可以互相转换的状态就可以,采用深搜,
设pre和now,
如果当前位置横着放,状态为11,那么上一行也必须是11
如果当前位置竖着放,状态为1,上一行为0
如果当前位置不放,那么上一行此位置为1,当前位置为0
,然后从第0行全为1开始,因为这样转换之后的状态才能构成一个完整的棋盘。
#include <iostream>
#include <cstdio>
#include <cstring>
#define maxn 12
#define LL long long
using namespace std;
int h,w;
LL d[maxn][<<maxn];
LL cnt;
LL EX[][];
void dfs(int l,int now,int pre)
{
if(l>w)
return ;
if(l==w)
{
EX[cnt][]=pre;
EX[cnt++][]=now;
//cout<<pre<<" "<<now<<endl;
return ;
}
dfs(l+,((now<< )|),((pre<<) | )) ; //横放
dfs(l+,((now<<) |),(pre<<) ) ; //竖放
dfs(l+, (now<<) , ((pre<<)| )) ; //不放
}
void solve()
{
int s=(<<w)-;
d[][s]=;
for(int i=;i<h;i++)
for(int j=;j<cnt;j++)
{
d[i+][EX[j][]]+=d[i][EX[j][]];
}
// for(int j=0;j<cnt;j++)
// printf("%d %d\n",EX[j][1],EX[j][0]);
printf("%lld\n",d[h][s]);
}
int main()
{
while(~scanf("%d%d",&h,&w) && (h!= && w!=))
{
memset(d,,sizeof(d));
// if(h>w)
// swap(h,w);
cnt=;
dfs(,,);
solve();
}
return ;
}
poj 2411((多米诺骨牌问题))的更多相关文章
- poj 1717==洛谷P1282 多米诺骨牌
Dominoes Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6571 Accepted: 2178 Descript ...
- 【Tsinghua OJ】多米诺骨牌(domino)问题
(domino.c/cpp)[问题描述] 小牛牛对多米诺骨牌有很大兴趣,然而她的骨牌比较特别,只有黑色和白色的两种.她觉 得如果存在连续三个骨牌是同一种颜色,那么这个骨牌排列便是不美观的.现在她有n个 ...
- 省选训练赛第4场D题(多米诺骨牌)
题目来自FZU2163 多米诺骨牌 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Vasya很喜欢排多米诺 ...
- 【01背包】洛谷P1282多米诺骨牌
题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S1=6+1+1+1=9, ...
- 多米诺骨牌放置问题(状压DP)
例题: 最近小A遇到了一个很有趣的问题: 现在有一个\(n\times m\)规格的桌面,我们希望用\(1 \times 2\)规格的多米诺骨牌将其覆盖. 例如,对于一个\(10 \times 11\ ...
- P1282 多米诺骨牌 (背包变形问题)
题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S1=6+1+1+1=9, ...
- [LeetCode] Push Dominoes 推多米诺骨牌
There are N dominoes in a line, and we place each domino vertically upright. In the beginning, we si ...
- P1282 多米诺骨牌
P1282 多米诺骨牌 题目描述 多米诺骨牌有上下2个方块组成,每个方块中有1~6个点.现有排成行的 上方块中点数之和记为S1,下方块中点数之和记为S2,它们的差为|S1-S2|.例如在图8-1中,S ...
- [Luogu1282]多米诺骨牌(DP)
#\(\color{red}{\mathcal{Description}}\) \(Link\) 我们有一堆多米诺骨牌,上下两个部分都有点数,\(But\)我们有一个操作是可以对调上下的点数.若记一块 ...
- 「ZJOI2009」多米诺骨牌
「ZJOI2009」多米诺骨牌 题目描述 有一个n × m 的矩形表格,其中有一些位置有障碍.现在要在这个表格内 放一些1 × 2 或者2 × 1 的多米诺骨牌,使得任何两个多米诺骨牌没有重叠部分,任 ...
随机推荐
- hdu 2795线段树
#include<stdio.h> #define N 200005 int h,w,n; struct node { int x,y,max; }a]; int mmax(int e,i ...
- C#中将数字金额转成英文大写金额的函数
<span style="white-space:pre"> </span>/// <summary> /// 数字转金额大写 /// 调用示例 ...
- msp430入门编程12
msp430中C语言的模块化头文件及库文件12 msp430入门学习 msp430入门编程
- Flex使用cookie保存登状态
flex系统要实现普通html系统刷新页面保留登录信息,一个方法是借用js来操作cookie来实现,下边是一个实现的例子: 第一步:在主index.html里边加上两个js方法 //获取cookie内 ...
- codeforces 1041 c 乱搞
#include <bits/stdc++.h> using namespace std; struct po { int val; int id; }; po a[]; vector&l ...
- P1918 保龄球 洛谷
https://www.luogu.org/problem/show?pid=1918 题目描述 DL 算缘分算得很烦闷,所以常常到体育馆去打保龄球解闷.因为他保龄球已经打了几十年了,所以技术上不成问 ...
- Search in Rotated Sorted Array(二分查找)
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- [Poj1185][Noi2001]炮兵阵地(状压dp)
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 29476 Accepted: 11411 Descriptio ...
- Linux查看日志三种命令(转载)
第一种:查看实时变化的日志(比较吃内存) 最常用的: tail -f filename (默认最后10行,相当于增加参数 -n 10) Ctrl+c 是退出tail命令 其他情况: tail -n 2 ...
- JavaScript Prototype in Plain Language
非常好的文章: http://javascriptissexy.com/javascript-prototype-in-plain-detailed-language/ jan. 25 2013 14 ...