#K36427. Count Ways to Fill Time Slots
Count Ways to Fill Time Slots
Count Ways to Fill Time Slots
You are given a collection of songs and several time slots. Each song has a duration and each time slot requires a combination of songs whose total duration exactly matches the slot's duration. Each song can be used at most once in forming a combination and different orders of the same subset of songs are considered identical.
Your task is to determine, for each time slot, the number of distinct ways to pick a subset of songs that perfectly fills the slot.
Note: Because the number of songs is relatively small, you may generate all possible subsets of songs.
Mathematically, for a given slot with required duration \( S \), you need to count how many subsets \( I \subseteq \{1, 2, \dots, N\} \) satisfy \[ \sum_{i \in I} d_i = S \] where \( d_i \) is the duration of the \( i\)-th song.
inputFormat
The input is given from standard input (stdin) and follows this format:
- The first line contains an integer \( T \) representing the number of test cases.
- For each test case:
- The first line contains two integers \( N \) and \( M \), where \( N \) is the number of songs and \( M \) is the number of time slots.
- The second line contains \( N \) integers, each indicating the duration of a song.
- The third line contains \( M \) integers, each indicating the required duration of a time slot.
outputFormat
For each test case, output one line containing \( M \) integers separated by a space. Each integer represents the number of ways to achieve the corresponding time slot's required duration using a subset of songs.
## sample1
4 2
30 40 20 10
50 60
2 2
</p>