Tri Tiling

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

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
 
Source
 
思路详见:动态规划
我的代码:
const int maxn = ;

int dp[maxn][];

void init() {
dp[][] = dp[][] = ;
dp[][] = ;
dp[][] = dp[][] = ;
dp[][] = ;
for (int i = ; i <= ; i ++) {
dp[i][] = dp[i-][] + dp[i-][] + dp[i-][];
dp[i][] = dp[i-][];
dp[i][] = dp[i-][] + dp[i][];
}
} int main() {
int n;
init();
while (~scanf("%d", &n)) {
if (n == -) break;
printf("%d\n", dp[n][]);
}
return ;
}

Discuss里的代码:

const int MAX=;
int s[MAX];
int main()
{
int i,n;
s[]=;
s[]=;
for(i=;i<MAX;i+=)
{
s[i]=*s[i-]-s[i-];
}
while(cin>>n,n>=)
{
if(n&)
cout<<<<endl;
else
cout<<s[n]<<endl;
}
return ;
}

最新文章

  1. windows如何远程桌面mac
  2. visual studio 2015中的webapi生成helpPage,页面不显示方法说明问题解决
  3. 7.js模式-装饰者模式
  4. 【过程改进】10分钟进阶Nuget
  5. 浅析MongoDB数据库的海量数据存储应用
  6. Python学习总结2:raw_input() 与 input()
  7. web server与app server有什么不同
  8. Android开发-API指南-&lt;supports-gl-texture&gt;
  9. shader复杂与深入:Normal Map(法线贴图)1
  10. SVN库迁移整理方法总结
  11. TimeZone 时区 (JS .NET JSON MYSQL)
  12. CompareValues标签对Model中的属性进行验证
  13. xml错误之cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element &#39;mvc:annotation-driven&#39;.
  14. 下载了好久的IntelliJ IDEA一直没用
  15. HTC脚本介绍和入门示例
  16. 阿里直播在线人数只统计rtmp格式的播放源
  17. 6款漂亮HTML CSS样式用户留言表单
  18. 在ant编译java文件时产生debug信息
  19. python learning IO.py
  20. std::function 使用_

热门文章

  1. 第二篇 Fiddler配置_浏览器&amp;手机
  2. Linux 进程--父进程查询子进程的退出状态
  3. Nginx 配置 HTTPS自签名证书
  4. WEBSTORM中html文件运行之后出现乱码的问题解决
  5. NAPT 分为锥型(Cone)和 对称型(Symmetric)
  6. C&amp;C++——基本说明
  7. CentOs7 minimal安装后没有ifconfig命令解决方法
  8. 从零开始学习MXnet(二)之dataiter
  9. Codeforces Round #532 (Div. 2) 题解
  10. typescript的入门