HDU1143(3*N的地板铺1*2的砖)
2024-08-28 01:24:54
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 ;
}
最新文章
- windows如何远程桌面mac
- visual studio 2015中的webapi生成helpPage,页面不显示方法说明问题解决
- 7.js模式-装饰者模式
- 【过程改进】10分钟进阶Nuget
- 浅析MongoDB数据库的海量数据存储应用
- Python学习总结2:raw_input() 与 input()
- web server与app server有什么不同
- Android开发-API指南-<;supports-gl-texture>;
- shader复杂与深入:Normal Map(法线贴图)1
- SVN库迁移整理方法总结
- TimeZone 时区 (JS .NET JSON MYSQL)
- CompareValues标签对Model中的属性进行验证
- 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;.
- 下载了好久的IntelliJ IDEA一直没用
- HTC脚本介绍和入门示例
- 阿里直播在线人数只统计rtmp格式的播放源
- 6款漂亮HTML CSS样式用户留言表单
- 在ant编译java文件时产生debug信息
- python learning IO.py
- std::function 使用_
热门文章
- 第二篇 Fiddler配置_浏览器&;手机
- Linux 进程--父进程查询子进程的退出状态
- Nginx 配置 HTTPS自签名证书
- WEBSTORM中html文件运行之后出现乱码的问题解决
- NAPT 分为锥型(Cone)和 对称型(Symmetric)
- C&;C++——基本说明
- CentOs7 minimal安装后没有ifconfig命令解决方法
- 从零开始学习MXnet(二)之dataiter
- Codeforces Round #532 (Div. 2) 题解
- typescript的入门