HDU 2046 递推

骨牌铺方格

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


Problem Description
在2×n的一个长方形方格中,用一个1× 2的骨牌铺满方格,输入n ,输出铺放方案的总数.
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
 
Input
输入数据由多行组成,每行包含一个整数n,表示该测试实例的长方形方格的规格是2×n (0<n<=50)。
 
Output
对于每个测试实例,请输出铺放方案的总数,每个实例的输出占一行。
 
Sample Input
1 3 2
 
Sample Output
1 3 2
 
Author
lcy
 
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<vector>
 6 #include<cstdlib>
 7 #include<math.h>
 8 using namespace std;
 9 const int inf=0x3f3f3f3;
10 const int maxn=57;
11 long long dp[maxn];
12 long long slove(int n)
13 {
14     dp[1]=1;dp[2]=2;
15     for(int i=3;i<=n;i++)
16     {
17         dp[i]=dp[i-1]+dp[i-2];
18     }
19     return dp[n];
20 }
21 int main()
22 {
23     int n;
24     while(~scanf("%d",&n)){
25         if(n==1){printf("1
");continue;}
26         if(n==2) {printf("2
");continue;}
27         long long ans=slove(n);
28         cout<<ans<<endl;
29     }
30 }
原文地址:https://www.cnblogs.com/codeyuan/p/4358089.html