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 |
贴Java代码。O(K*N)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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator