Odd subsequences

3.9

12 votes
Combinatorics, Mathematics, Dynamic Programming, 2D dynamic programming, Algorithms
Problem

You are given an array consisting of elements. Find the number of subsequences of length  with odd sum modulo .

Input format

  • The first line contains the number of test cases
  • The first line of each test case contains two integers  denoting the number of elements in array and denoting the length of subsequence.
  • The second line of each test case contains space-separated integers of array .

Output format

Print lines. For each test case:

  • Print a single integer denoting the number of subsequences of length with odd sum modulo .

Constraints

  • Sum of N over all test cases will not exceed 1000.
Sample Input
1
5 2
1 2 3 4 5
Sample Output
6
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

[1,2],[1,4],[2,3],[2,5],[3,4] and [4,5]

Editor Image

?