Number of Sequences Related to Palindromes
Time limit0.25sMemory limit512 MB
Count length-N sequences with values up to M such that every length-K window is a palindrome, modulo 1e9+7.
- Level
Medium6 of 10
- Topics
- Combinatorics, Math, Union-find, Dynamic programming
- Solved
- No attempts yet
Problem
Given N, M, and K, count the number of sequences A that satisfy the following conditions.
- The length of A is N.
- A consists of natural numbers less than or equal to M.
- Every contiguous subsequence of A of length K is a palindrome.
Input
The first line contains N, M, and K.
Output
Print the number of sequences A modulo on the first line.