您的位置:首页 > 其它

HDU 2046 骨牌铺方格(递推)

2016-02-09 12:10 471 查看
题目:HDU-2046 骨牌铺方格

题目链接: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): 40817    Accepted Submission(s): 19793


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

 

很简单很简单,递推关系式为,f(n)=f(n-1)+f(n-2),画图画两个就推出来,唉,画的心累。

#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<math.h>
using namespace std;
const int maxn=55;
long long ans[maxn];
int n;
int main(){
for(int i=1;i<=50;i++)
if(i==1) ans[i]=1;
else if(i==2) ans[i]=2;
else
ans[i]=ans[i-1]+ans[i-2];
while(cin>>n){
cout<<ans
<<endl;
}
return 0;
}


加油~
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: