骨牌鋪方格
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; }