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