You are given three integers n
, m
, k
. A good array arr
of size n
is defined as follows:
arr
is in the inclusive range [1, m]
.k
indices i
(where 1 <= i < n
) satisfy the condition arr[i - 1] == arr[i]
.Return the number of good arrays that can be formed.
Since the answer may be very large, return it modulo 109 + 7
.
Example 1:
Input: n = 3, m = 2, k = 1
Output: 4
Explanation:
[1, 1, 2]
, [1, 2, 2]
, [2, 1, 1]
and [2, 2, 1]
.Example 2:
Input: n = 4, m = 2, k = 2
Output: 6
Explanation:
[1, 1, 1, 2]
, [1, 1, 2, 2]
, [1, 2, 2, 2]
, [2, 1, 1, 1]
, [2, 2, 1, 1]
and [2, 2, 2, 1]
.Example 3:
Input: n = 5, m = 2, k = 0
Output: 2
Explanation:
[1, 2, 1, 2, 1]
and [2, 1, 2, 1, 2]
. Hence, the answer is 2.
Constraints:
1 <= n <= 105
1 <= m <= 105
0 <= k <= n - 1