Pages

Sunday 9 September 2012

UVA - 10359 -Tiling


import java.io.*;
import java.math.BigInteger;
import java.util.IllegalFormatException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFileChooser;
import javax.swing.JOptionPane;

public class Main {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        TextIO.readStream(System.in);
        BigInteger[] arr=new BigInteger[251];
        for(int i=0;i<251;i++){
            arr[i]=BigInteger.ZERO;
        }
        while(true){
          int n=0;
          try{
          n=TextIO.getInt();
          }catch(Exception e){
              break;
          }
           BigInteger calct=calc(n,arr);
           System.out.println(calct);
        }
    }
   
   static BigInteger calc(int x,BigInteger[]arr){
        if(arr[x].compareTo(BigInteger.ZERO)==1)
            return arr[x];
        if(x<=0 ||x==1)
            return BigInteger.ONE;
        arr[x]=(BigInteger.valueOf(2).multiply(calc(x-2,arr)))
                .add(calc(x-1,arr));
        return arr[x];
               
    }
}

No comments:

Post a Comment