Tap here to switch tabs
Problem
Submissions

Problem: Count Arrays With K Matching Adjacent Elements

Try to solve the Count the Number of Arrays with K Matching Adjacent Elements problem.

Statement

You are given three integers n, m, and k.

An array arr of size n is called good if:

  • 1≤1 \leq arr[i] ≤\leq m for every 0≤0 \leq i << n.

  • There are exactly k indices i (0≤0 \leq i << n −1- 1) such that arr[i] = arr[i + 1].

Return the total number of good arrays. Since the answer can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq m ≤105\leq 10^5

  • 0≤0 \leq k ≤\leq n −1- 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Count Arrays With K Matching Adjacent Elements

Try to solve the Count the Number of Arrays with K Matching Adjacent Elements problem.

Statement

You are given three integers n, m, and k.

An array arr of size n is called good if:

  • 1≤1 \leq arr[i] ≤\leq m for every 0≤0 \leq i << n.

  • There are exactly k indices i (0≤0 \leq i << n −1- 1) such that arr[i] = arr[i + 1].

Return the total number of good arrays. Since the answer can be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq n ≤105\leq 10^5

  • 1≤1 \leq m ≤105\leq 10^5

  • 0≤0 \leq k ≤\leq n −1- 1