L - Tri Tiling
Time Limit:1000MS MemoryLimit:32768KB 64bit IO Format:%I64d& %I64u
Submit Status Practice HDU 1143
Appoint description:
Description
In how many wayscan you tile a 3xn rectangle with 2x1 dominoes? Here is a sample tiling of a3x12 rectangle.
Input
Input consistsof several test cases followed by a line containing -1. Each test case is aline containing an integer 0 ≤ n ≤ 30.
Output
For each testcase, output one integer number giving the number of possible tilings.
Sample Input
2
8
12
-1
Sample Output
3
153
2131
import java.util.*;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
int []a=new int [32];
a[0]=1;a[1]=0;a[2]=3;a[3]=0;a[4]=11;
int i,j,k;
for(i=6;i<=31;i+=2){
a[i]=a[i-2]*3;
k=0;
for(j=i-4;j>=0;j-=2)k+=a[j];
a[i]=a[i]+2*k;
}
while(in.hasNext()){
int n=in.nextInt();
if(n==-1)break;
System.out.println(a[n]);
}
}
}