http://acm.hdu.edu.cn/showproblem.php?pid=2046
骨牌铺方格
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 44570 Accepted Submission(s): 21619
Problem Description
在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
![](http://acm.split.hdu.edu.cn/data/images/C40-1003-1.jpg)
Input
输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。
Output
对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。
Sample Input
1 3 2
Sample Output
1 3 2
解题思路:
第n个有两种摆放方法
1.摆竖的,方案为dp[n-1]
2.摆横的,方案为dp[n-2]
1.摆竖的,方案为dp[n-1]
2.摆横的,方案为dp[n-2]
//2046 递推,2*n方块 (同2045方法)
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
typedef long long ll;
ll dp[52];
int n;
int main()
{
memset(dp,0,sizeof(dp));
dp[1]=1;
dp[2]=2;
dp[3]=3;
for (int i=4;i<=50;i++)
dp[i]=dp[i-1]+dp[i-2];
while (~scanf("%d",&n))
printf("%I64d\n",dp[n]);
return 0;
}