题目:
In how many ways can you tile a 2xn rectangle by 2x1 or 2x2 tiles?
Here is a sample tiling of a 2x17 rectangle.
代码:
import java.io.*; import java.math.*; import java.util.*; import java.text.*; public class Main{ public static void main(String[] args) { Scanner cin = new Scanner (new BufferedInputStream(System.in)); BigInteger[] dp=new BigInteger [300]; dp[0]=dp[1]= BigInteger.valueOf(1); for(int i=2;i<=250;i++) { dp[i]=dp[i-1].add(dp[i-2].multiply(BigInteger.valueOf(2))); } while(cin.hasNext()) { int n=cin.nextInt(); System.out.println(dp[n]); } } }
时间: 2024-10-12 23:39:18