6909.Meet in the Middle

Time Limit: 2s Memory Limit: 512MB

You are given an array of $n$ numbers. In how many ways can you choose a subset of the numbers with sum $x$ ?

Input Format(From the terminal/stdin)

The first input line has two numbers $n$ and $x$ : the array size and the required sum.

The second line has $n$ integers $t_1,t_2,\dots,t_n$ : the numbers in the array.

  • $1 \le n \le 40$
  • $1 \le x \le 10^9$
  • $1 \le t_i \le 10^9$

Output Format(To the terminal/stdout)

Print the number of ways you can create the sum $x$ .

Sample Input

Copy
4 5
1 2 3 2
 · \n
 · · · \n

Sample Output

Copy
3
 \n
Source: CSES, Advanced Techniques, 1628

Submit

请先 登录

© 2025 FAQs