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

贴Java代码。O(K*N)

Posted by haqishen at 2015-01-04 10:28:13 on Problem 3181
import java.math.BigInteger;
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);		
		int N = s.nextInt(), K = s.nextInt();
		
		BigInteger[] dp = new BigInteger[N+1];
		dp[0] = new BigInteger("1");
		for(int j = 1; j <= N; j++)
			dp[j] = new BigInteger("0");
		
		for(int i = 1; i <= K; i++){
			for(int j = 1; j <= N; j++){
				if(j>=i){
					dp[j] = dp[j].add(dp[j-i]);
				}
//				System.out.print(dp[j]+" ");
			}
//			System.out.println();
		}
		System.out.println(dp[N]);
	}

}

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