#3405

Count the Number of Arrays with K Matching Adjacent Elements

expert · 1230 · lc hard +32 · 58.4% accepted · 429 likes · top 55%

Description

You are given three integers n, m, and k. A good array arr of size n satisfies:

- Every element in arr lies in the range [1, m].

- Exactly k indices i (where 1 <= i < n) satisfy 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.

Code

1
2
3