#C6075. Counting the Number of Ways to Select Pots
Counting the Number of Ways to Select Pots
Counting the Number of Ways to Select Pots
You are given N pots each with a specific capacity. Your task is to determine the number of unique ways to select a subset of these pots such that the sum of their capacities is exactly T.
Formally, given an integer N representing the number of pots, an integer T representing the target total capacity, and an array capacities of N positive integers, find the number of subsets whose sum equals T. Mathematically, if we denote the capacities as \(a_1, a_2, \dots, a_N\), you need to count the number of index sets \(I \subseteq \{1,2,\dots,N\}\) such that:
[ \sum_{i \in I} a_i = T ]
Note that each pot can be chosen at most once.
Example:
Input: N = 4, T = 5, capacities = [1, 2, 3, 4] Output: 2
There are two subsets that sum to 5: [1, 4] and [2, 3].
inputFormat
The first line contains two space-separated integers N and T, where N is the number of pots and T is the target capacity sum.
The second line contains N space-separated integers representing the capacities of the pots.
outputFormat
Output a single integer that is the number of unique ways to select a subset of pots such that their total capacity is exactly T.
## sample4 5
1 2 3 4
2