Tri Tiling

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2834    Accepted Submission(s): 1603

Problem 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
 

参考:http://blog.csdn.net/chaoojie/article/details/8860935

当dp[i] 划分成 2 和 i-2 后,再划分成 4和i-4时,4的部分,不能再划分成2 , 2 组合,这样就会和前面的2 和i-2 重复,同样,划分过2 ,i-2 以及 4, i-4 后,再划分 6, i-6时,也不能划分成 2,2,2 以及 2, 4或 4, 2,同理,划分成8, i-8....

把 4, 6, 8.... 看成一整块,就有下图两种情况(正着,倒着)

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int main()
{
int dp[35];
int t;
dp[0]=1;
dp[1]=0;
dp[2]=3;
for(int i=3;i<=30;i++)
{
if(i%2)
{
dp[i]=0;
continue;
}
dp[i]=dp[2]*dp[i-2];
for(int j=i-4;j>=0;j-=2)
dp[i]+=2*dp[j];
}
while(scanf("%d",&t)&&t!=-1)
{
cout<<dp[t]<<endl;
}
return 0;
}

  

最新文章

  1. 暴风冯鑫:去美国香港的99%都亏,互联网公司打死都要回A股
  2. BZOJ 4034 BIT &amp; Dfs序
  3. linux-6的yum软件仓库
  4. 用C++为nodejs 写组件,提高node处理效率
  5. socket学习笔记——select与epoll函数的使用(linux)
  6. Linux Hugetlbfs内核源码简析-----(二)Hugetlbfs挂载
  7. 【转载】【JQuery学习】jQuery插件开发
  8. PowerDesigner技巧
  9. hdu 4268 Alice and Bob(multiset|段树)
  10. IOS 固定定位底部input输入框,获取焦点时弹出的输入法键盘挡住input
  11. .net core使用orm操作mysql数据库
  12. 2.5 Cesium视域分析的实现
  13. BZOJ 3674 可持久化并查集
  14. Liunx 更新环境时用到的命令
  15. Java基础—集合
  16. 打劫房屋 &#183; House Robber
  17. Win10安装docker步骤
  18. [19/04/28-星期日] GOF23_结构型模式(享元模式)
  19. fail2ban 防暴力破解总结
  20. Apache2.4部署python3.6+django2.0项目

热门文章

  1. android中单元測试中的断言assert的使用与扩展
  2. php开启短标签
  3. HDU 1231——最大连续子序列(DP)
  4. Codeforces 455B A Lot of Games 字典树上博弈
  5. Python执行系统命令并获得输出的几种方法
  6. python 三维坐标图
  7. Kentico中的skin.css的加载
  8. HDU 5073 数学题
  9. [Codeforces 623A] Graph and String
  10. [Codeforces 140C] New Year Snowmen