Time Limit: 1000 ms Memory Limit: 32768 KiB
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
#include<bits/stdc++.h>
using namespace std;
map<int,long long> a;
long long f(int n){
a[1] = 1;
a[2] = 2;
for(int i=3;i<=50;i++)
{
a[i] = a[i-1]+a[i-2];
}
return a[n];
}
int main(){
int n;
while(cin>>n){
cout<<f(n)<<endl;
}
}