UVA 10918
题目介绍:
In how many ways can you tile a 3 × n rectangle with 2 × 1 dominoes?
Here is a sample tiling of a 3 × 12 rectangle.
Input
Input consists of several test cases followed by
a line containing ‘-1’. Each test case is a line
containing an integer 0 ≤ n ≤ 30.
Output
For each test case, output one integer number
giving the number of possible tilings.
大意:
n为奇数时,面积/2有余数,不成立。
n为偶数时,去掉2,2可以有3种构成,>=4的偶数的部分有两种构成
F(n)=3F(n-2)+2F(n-4)+…+2*F(0);
AC代码:
#include<iostream>
#include<cstring>
using namespace std;
int main(){
int ss[35]={0};
ss[0]=1;
for(int i=1;i<=30;i++){
if(i%2)ss[i]=0;
else{
if(i>=2)ss[i]+=3*ss[i-2];
if(i>=4)ss[i]+=2*ss[i-4];
for(int j=6;j<=i;j+=2)
ss[i]+=2*ss[i-j];
}
}
int n;
while(scanf("%d",&n)==1&&n!=-1){
cout<<ss[n]<<endl;
}
return 0;
}