AcWing 279. 自然数拆分
原题链接
简单
作者:
花酱
,
2024-12-11 21:08:37
,
所有人可见
,
阅读 2
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n= scan.nextInt();
int mod= 0x80000000;
if(n==1){
System.out.println(0);
return ;
}
int[] nums=new int[n-1];
for (int i = 0; i < nums.length; i++) {
nums[i]=i+1;
}
long[][] dp=new long[n][n+1];
dp[0][0]=1;
for (int i = 1; i < n; i++) {
for (int j = 0; j <= n; j++) {
//不选i
dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
//选i
if(j>=nums[i-1]){
dp[i][j]=(dp[i][j]+dp[i][j-nums[i-1]])%mod;
}
}
}
System.out.println(dp[n-1][n]);
}
}