AcWing 278. 数字组合
原题链接
简单
作者:
花酱
,
2024-12-11 20:45:54
,
所有人可见
,
阅读 2
import java.util.Scanner;
class Main{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int n= scan.nextInt();
int m=scan.nextInt();
int[] nums=new int[n];
for (int i = 0; i < n; i++) {
nums[i]= scan.nextInt();
}
int[][] dp=new int[n+1][m+1];
dp[0][0]=1;
for (int i = 1; i <= n; i++) {
for (int j = 0; j <= m; j++) {
//不选i
dp[i][j]+=dp[i-1][j];
//选i
if(j>=nums[i-1]){
dp[i][j]+=dp[i-1][j-nums[i-1]];
}
}
}
System.out.println(dp[n][m]);
}
}