博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU_1143_tri tiling
阅读量:7013 次
发布时间:2019-06-28

本文共 1308 字,大约阅读时间需要 4 分钟。

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
#include
#include
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<
<

  

转载于:https://www.cnblogs.com/jasonlixuetao/p/4707552.html

你可能感兴趣的文章
winform GDI基础(四)简单截屏
查看>>
WEB前端开发规范文档
查看>>
最大熵模型原理
查看>>
Mysql 用户和权限管理
查看>>
python内建函数
查看>>
Sencha-数据-Proxy(代理) (官网文档翻译25)
查看>>
[C#]richtextbox实现拖放
查看>>
Python ImportError: cannot import name *
查看>>
Hadoop生态圈-Flume的组件之拦截器与选择器
查看>>
Java基础-SSM之mybatis多对多关联
查看>>
Android微信支付SDK开发
查看>>
[Android Pro] 横竖屏切换时,禁止activity重新创建,android:configChanges="keyboardHidden|orientation" 不起作用...
查看>>
上学路线
查看>>
相对路径 System.Web HttpServerUtilityBase Server.MapPath("~/")
查看>>
【转】Spring中事务与aop的先后顺序问题
查看>>
IIS服务器管理学习
查看>>
poj3252-Round Number 组合数学
查看>>
程序猿和星座之间不可不谈的事
查看>>
log4j.properties 日志分析
查看>>
pdfminer import报错解决方法
查看>>