要注意的就是会越界,使用long都不可以
对于java来说最方便的就是大数处理了
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
int money = sc.nextInt();
int cost = sc.nextInt();
BigInteger[] dp = new BigInteger[money + 1];
Arrays.fill(dp,BigInteger.valueOf(0));
dp[0] = BigInteger.valueOf(1);
for (int i = 1; i <= cost; i++ ){
for (int j = 0; j <= money; j++){
if (j >= i){
dp[j] = dp[j].add(dp[j - i]);
}
}
}
if (money == 0){
System.out.println(0);
} else {
System.out.println(dp[money]);
}
}
}