842. Find the Number of K-Even Arrays
Given three integers n, m, and k.
An array arr is called k-even if there are exactly k indices such that, for each of these indices i (0 <= i < n - 1): (arr[i]×arr[i+1])−arr[i]−arr[i+1] is even.
Return the number of possible k-even arrays of size n where all elements are in the range [1, m].
Since the answer may be very large, return it modulo 10⁹ + 7.
Example 1:
Input: n = 4, m = 5, k = 3
Output: 16
Explanation:
The 16 possible 3-even arrays are:
[2, 2, 2, 2]
[2, 2, 2, 4]
[2, 2, 4, 2]
[2, 2, 4, 4]
[2, 4, 2, 2]
[2, 4, 2, 4]
[2, 4, 4, 2]
[2, 4, 4, 4]
[4, 2, 2, 2]
[4, 2, 2, 4]
[4, 2, 4, 2]
[4, 2, 4, 4]
[4, 4, 2, 2]
[4, 4, 2, 4]
[4, 4, 4, 2]
[4, 4, 4, 4]
Example 2:
Input: n = 6, m = 1, k = 0
Output: 1
Explanation: The only 0-even array is [1,1,1,1,1,1].
Now Your Turn!
Pick the correct output for the given inputInput: n = 5, m = 2, k = 2
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- 1 <= n <= 750
- 0 <= k <= n - 1
- 1 <= m <= 1000