解题思路:
注意事项:
参考代码:
import java.util.Scanner; public 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]; int[] dp = new int[m + 1]; for(int i = 0;i < n;i++) nums[i] = scan.nextInt(); dp[0] = 1; for(int i = 0;i < n;i++){ for(int j = m;j >= nums[i] ;j--){ dp[j] += dp[j - nums[i]]; } } System.out.println(dp[m]); } }
0.0分
1 人评分