Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

体测前贴个代码攒攒RP,JAVA大整数+动规过的

Posted by 1000010314 at 2012-04-08 13:07:21 on Problem 2680
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator