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. CSS实现标题/段落省略效果的三剑客

    white-space: nowrap;overflow:hidden;text-overflow:ellipsis; 效果如下:

  2. 安卓点击home键重启

    主要原因是:每次启动Intent导致新创建Task的时候,该Task会记录导致其创建的Intent:而如果后续需要有一个新的与创建Intent完全一致(完全一致定位为:启动类,action.categ ...

  3. spark核心优化详解

    大家好!转眼又到了经验分享的时间了.吼吼,我这里没有摘要也没有引言,只有单纯的经验分享,请见谅哦! 言归正传,目前在大数据领域能够提供的核心计算的工具,如离线计算hadoop生态圈的mr计算模型,以及 ...

  4. vue开发记录--element-ui的form表单label和placeholder国际化遇到的小问题

    <el-form-item label="$t('permission.employeeName')"> <el-input v-model="form ...

  5. VisualStudioCode创建的asp.net core项目部署到linux,使用nginx代理

    1.准备工作: a:使用VisualStudioCode创建asp.net core项目,并使用命令“dotnet publish”发布(可以参考前面两篇文章). 如:dotnet publish - ...

  6. 学习animation、transition、transform和@keyframes的使用

    当我们需要给页面添加动画效果时,需要用到CSS3的animation样式属性: 例如: animation: test 2s infinite; 其中test是动画的名称,2s是动画的时长,infin ...

  7. Keras RetinaNet github项目安装

    在存储库目录/keras-retinanet/中,执行pip install . --user 后,出现错误: D:\>cd D:\JupyterWorkSpace\keras-retinane ...

  8. Mysql 5.7优化

    为了达到数据库胡最佳性能 1. 普通用户通过配置软件与硬件来实现 2. 高级用户会寻求机会改善MySQL本身,开发自己的数据存储引擎,硬件应用. 在数据库层面的优化 1. 表设计,通常列有适合的数据类 ...

  9. 谷歌将一些弱小的库从安卓代码移除Google Removes Vulnerable Library from Android

    Google this week released the November 2018 set of security patches for its Android platform, which ...

  10. Navicat for MySQL下载安装和破解教程

    1.进https://navicatformysql.en.softonic.com/官网 2.第二步 3.第三步等待下载完成 4.第四步双击 二,破解 1.链接:https://pan.baidu. ...