Problem · Dynamic Programming
Count Integer Sequences
Learn this problemProblem statement
Print the number of integer sequences of length N, A = {A1, A2, A3...., AN} possible where the Sequence A should follow the conditions below:
- All elements in
Ashould be between0andM(inclusive) - XOR of all the elements in
Ais equal toX
Print the number of integer sequence satisfying these conditions modulo 998244353.
Input Format:
N, M , X
Function
countIntegerSequences(N: long, M: long, X: long) → int
Complete the function countIntegerSequences in the editor.
countIntegerSequences has the following parameters:
N: the length of the sequenceM: the maximum value of the elements in the sequenceX: the XOR value to be achieved
Returns
int: the number of integer sequences modulo 998244353
Examples
Example 1
N = 200M = 9000606388LX = 317329110return = 788002104The output is the number of integer sequences of length
N that satisfy the given conditions modulo 998244353.Example 2
N = 3M = 3X = 2return = 5The 5 sequences of length
N(3) that satisfy both the conditions are:
(0, 0, 2), (0, 1, 3), (1, 1 ,2), (2, 2, 2), (2, 3, 3).
All the sequences are of length N(3), all the elements in the sequence are between 0 and M(3) inclusive and xor of all the elements in the individual sequence is equal to X(2).