Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
体测前贴个代码攒攒RP,JAVA大整数+动规过的import java.io.PrintWriter; import java.math.BigInteger; import java.util.Arrays; import java.util.Scanner; public class Main { static Scanner cin=new Scanner(System.in); static PrintWriter cout=new PrintWriter(System.out, true); static BigInteger[] data; final static BigInteger two=new BigInteger("2"); final static BigInteger negone=new BigInteger("-1"); public static BigInteger dp(int n) { if(data[n].compareTo(BigInteger.ZERO)>=0) { return data[n]; } return data[n]=dp(n-2).add(two.pow(n-2)); } public static void main(String[] args) { data=new BigInteger [1001]; Arrays.fill(data,negone); data[1]=BigInteger.ONE; data[0]=BigInteger.ZERO; data[2]=BigInteger.ONE; int n; while(cin.hasNext()) { n=cin.nextInt(); cout.println(dp(n-1)); } } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator