JAVA UVA練習
2016年1月21日 星期四
b587: 10918 - Tri Tiling
內容 :
給你一個3 * n的地面,用1 * 2的地板磚鋪滿,問有幾種方法。
輸入說明 :
每行有一個整數n,代表為
3 * n的地面,0 ≤ n ≤ 30,n=-1時代表輸入結束
輸出說明 :
請對每一個輸入,輸出可能的排法數
範例輸入 :
2 8 12 -1
範例輸出:
3 153 2131
提示 :
DP
標籤:
uva
出處:
uva10918
(管理:
pcshic
)
import java.util.Scanner;
public class UVAb587 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int n;
int[] f=new int[32];
f[0]=1; f[2]=3;
for(int i=4;i<32;i+=2)
f[i]=4*f[i-2]-f[i-4];
while((n=sc.nextInt())!=-1){
System.out.println(f[n]);
}
}
}
沒有留言:
張貼留言
較新的文章
較舊的文章
首頁
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言