Description

In how many ways can you tile a 3xn rectangle with 2x1 dominoes? 
Here is a sample tiling of a 3x12 rectangle.

Input

Input consists of several test cases followed by a line containing -1. Each test case is a line containing an integer 0 <= n <= 30.

Output

For each test case, output one integer number giving the number of possible tilings.

Sample Input

2
8
12
-1

Sample Output

3
153
2131

题解

看了别人的博客都是递推啥的,

之前自己推了半天推不出来,智商捉鸡,就放着没做了

直到我做了POJ 2411后

再回来看这题,就是把宽度设为3而已...

#include <iostream>
#include <cstdio> //EOF,NULL
#include <cstring> //memset
#include <cmath> //ceil,floor,exp,log(e),log10(10),hypot(sqrt(x^2+y^2)),cbrt(sqrt(x^2+y^2+z^2))
#include <algorithm> //fill,reverse,next_permutation,__gcd,
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
using namespace std;
#define rep(i, a, n) for (int i = a; i < n; ++i)
#define sca(x) scanf("%d", &x)
#define sca2(x, y) scanf("%d%d", &x, &y)
#define sca3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pri(x) printf("%d\n", x)
#define pb push_back
#define mp make_pair
typedef pair<int, int> P;
typedef long long ll;
const ll inf = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+;
const int maxn = ;
const int N = 1e4 + ;
int t, n, m;
int cnt, ans, ed;
ll dp[][<<];
int path[][];
int h, w;
void dfs(int l, int now, int pre)
{
if (l > w) {
return;
}
if (l == w) {
path[cnt][] = pre;
path[cnt++][] = now;
return;
}
dfs(l + , (now << )|, (pre << )|); // 竖放,当前行为1,上一行为0
dfs(l + , (now << )|, (pre << )); // 横放 当前行和上一行都为11
dfs(l + , (now << ), (pre << )|); //不放,上一行为1,当前行为0
} int main()
{
while (sca(h) && h != -)
{
w = ;
cnt = ;
dfs(, , );
memset(dp, , sizeof dp);
ed = ( << w) - ;
dp[][ed] = ;
for (int i = ; i < h; i++)
{
for (int j = ; j < cnt; j++)
{
dp[i + ][path[j][]] += dp[i][path[j][]];
}
}
printf("%lld\n", dp[h][ed]);
}
return ();
}

POJ 2663 Tri Tiling 【状压DP】的更多相关文章

  1. POJ 3254 Corn Fields (状压dp)

    题目链接:http://poj.org/problem?id=3254 给你n*m的菜地,其中1是可以种菜的,而菜与菜之间不能相邻.问有多少种情况. 状压dp入门题,将可以种菜的状态用一个数的二进制表 ...

  2. POJ 3254 - Corn Fields - [状压DP水题]

    题目链接:http://poj.org/problem?id=3254 Time Limit: 2000MS Memory Limit: 65536K Description Farmer John ...

  3. [ An Ac a Day ^_^ ] POJ 3254 Corn Fields 状压dp

    题意: 有一块n*m的土地 0代表不肥沃不可以放牛 1代表肥沃可以放牛 且相邻的草地不能同时放牛 问最多有多少种放牛的方法并对1e8取模 思路: 典型的状压dp 能状态压缩 能状态转移 能状态压缩的题 ...

  4. poj 3254Corn Fields (入门状压dp)

    Farmer John has purchased a lush ≤ M ≤ ; ≤ N ≤ ) square parcels. He wants to grow some yummy corn fo ...

  5. POJ 1684 Corn Fields(状压dp)

    描述 Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ ...

  6. POJ 2923 Relocation(状压DP)题解

    题意:有2辆车运货,每次同时出发,n(<10),各自装货容量c1 c2,问最少运几次运完. 思路:n比较小,打表打出所有能运的组合方式,用背包求出是否能一次运走.然后状压DP运的顺序. 代码: ...

  7. poj 2663 Tri Tiling (状压dp+多米诺骨牌问题+滚动数组反思)

    本来直接一波状压dpAC的 #include<cstdio> #include<cstring> #include<algorithm> #define REP(i ...

  8. POJ 2663 Tri Tiling

                                                                                    Tri Tiling   Time Li ...

  9. POJ 2663 Tri Tiling 矩阵快速幂 难度:3

    Tri Tiling Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7841   Accepted: 4113 Descri ...

随机推荐

  1. Eclipse中STM32工程建立步骤

    前段时间一直在折腾linux系统上STM32的开发,网上一顿搜,费劲九牛二虎之力终于把环境搭好了(现在都有点忘了,后面再折腾环境搭建一定要写个教程,今天先不写了). 自从环境搭好之后,就基本抛弃MDK ...

  2. Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0

    原因:JDK版本不兼容.运行的Java Class文件采用高版本的JDK编译,然后在低版本的JRE环境中运行,有时会报此错误. 解决:1)升级JDK 2)调整Eclipse中Java Compiler ...

  3. vue-cli +echarts-amap集成echarts和高德地图TypeError: Cannot read property 'dataToPoint' of null解决方案

    由于项目的需求,需要做一种迁徙效果, 最后我们采用了组件化开发,可以说这个坑自己一个人踩,有点累,但也收获不少. vue-cli +echarts-amap集成echarts和高德地图,出现报错,错误 ...

  4. NSRunLoop 在mac command line tool上的部分运用

    首先RunLoop相关博客参考这篇https://blog.csdn.net/lengshengren/article/details/12905627. 最近开发了一个mac上的命令行工具,我在主线 ...

  5. iStatistica Pro for mac(mac系统监视器)

    iStatistica Pro for mac是一款运行在Mac平台上的mac系统监视器,你可以使用iStatistica pro for mac破解版轻松查看PAM使用情况.CPU信息.磁盘信息.本 ...

  6. attr 和 prop的使用区别

    自带的属性,用prop:自定义的属性,用attr.

  7. JavaScript 区分中英文字符的两种方法: 正则和charCodeAt()方法

    正则无疑是最强大的判断各种条件的方法, 最近也在研习它, 虽然枯燥, 但仍有乐趣. 用它来判断一个双字节的中文字符也是轻而易举地. 而判断中文字符,  简单且执行效率高. regExpForm.onb ...

  8. dom渲染方面的优化浅谈

    今天分享一个面试经验,上周面试中一位印象很深的面试官(主要长得很帅),问我了一个我至今印象很深刻的问题,当然不是什么你之后的职业规划啊,你工作中遇到过哪些问题啊之类的.原起于一道面试题,小伙伴们可以想 ...

  9. Spring Security 内置过滤器表

    别名 Filter 类 CHANNEL_FILTER ChannelProcessingFilter SECURITY_CONTEXT_FILTER SecurityContextPersistenc ...

  10. 灵雀云:etcd 集群运维实践

    [编者的话]etcd 是 Kubernetes 集群的数据核心,最严重的情况是,当 etcd 出问题彻底无法恢复的时候,解决问题的办法可能只有重新搭建一个环境.因此围绕 etcd 相关的运维知识就比较 ...