骨牌铺方格
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 18 Accepted Submission(s) : 9
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
Problem Description
例如n=3时,为2× 3方格,骨牌的铺放方案有三种,如下图:
Input
Output
Sample Input
1 3 2
Sample Output
1 3 2
思路分析:其实此题为简单的递推问题,关键在于开始要算出它排的序列数。思路要清晰,还有递推的关键在于找前后两个数据的联系。还有要用长整型或者64位的。
代码:#include<iostream> #include<string.h> #include<stdio.h> using namespace std; int main() { __int64 a[100],n,i; while(scanf("%I64d",&n)!=EOF) { a[1]=1; a[2]=2; for(i=3;i<=n;i++) a[i]=a[i-1]+a[i-2]; printf("%I64d\n",a[n]); } return 0; }