Harder Staircase Numbers
Time limit2sMemory limit1024 MB
Count the length-N B-ary staircase numbers (adjacent digits differ by 1, no leading zero) that use every digit from 0 to B-1, modulo M.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Combinatorics, Bit manipulation
- Solved
- No attempts yet
Problem
Consider the number 45656. The difference between every pair of adjacent digits is 1. A number like this is called a staircase number.
Sejun wants to know how many B-ary staircase numbers of length exist in which every one-digit number from 0 to appears as a digit.
Given , , and , write a program that finds the number of B-ary staircase numbers of length that contain every digit from 0 to , modulo . (A number cannot start with 0.)
Input
The first line contains natural numbers , , and . (, , )
Output
Print the answer on the first line.