某君有 n 个互不相同的正整数,现在他要从这 n 个正整数之中无重复地选取任意个数,并仅通过加法凑出整数 X。求某君有多少种不同的方案来凑出整数 X。
输入格式
第一行,输入两个整数 n,X(1≤n≤20,1≤X≤2000)。
接下来输入 n 个整数,每个整数不超过 100100。
输出格式
输出一个整数,表示能凑出 X 的方案数。
样例输入
6 6 1 2 3 4 5 6
样例输出
4
import java.util.Scanner; public class Main { static int n; static int x; static int[] arr; static int count; public static void main(String[] args) { Scanner sc = new Scanner(System.in); n = sc.nextInt(); x = sc.nextInt(); arr = new int[n]; for(int i = 0; i < arr.length; i ++) { arr[i] = sc.nextInt(); } dfs(0, 0); System.out.println(count); } private static void dfs(int step, int sum) { if(step == arr.length) { if(sum == x) { count ++; } return; } if(sum > x) return; dfs(step + 1, sum); dfs(step + 1, sum + arr[step]); } }