-1

Find the number of subsequences of size n, with sum such that after taking modulo m, the sum became greater or equal to x.
Where:
1 <= n <= 42
1 <= m <= 10^9
0 <= x < m
How to solve this?

1 Answers1

1

This problem is easier to solve with a search technique called "Meet in the middle". As Peter de Rivaz suggests you can split up your input into two sets A and B, each with 21 or less elements.

Step 1:
There are 2^|A| combinations of elements in A, and for each of these calculate the sum mod m and store this in a table T. Sort the table T.

Step 2:
For each combination c of the 2^|B| combinations of elements of B, calculate the sum s of c mod m. Now you can determine the range i->j s.t. s + i >= x mod m, using binary search on T you can determine the number of table entries of T that are in the required range.

The running time of this is O(2^{n/2} * n) which for n = 42 is computable.

Christian Sloper
  • 7,440
  • 3
  • 15
  • 28