Similar numbers
Practice
4.5 (6 votes)
Implementation
Algorithms
Basics of bit manipulation
Dynamic programming
2d dynamic programming
Problem
87% Success 893 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code
You are given a telephone number of length \(N\). Assume that the two phone numbers are similar if the following conditions are met:
- They are different.
- The number of positions that contains different digits does not exceed \(K\).
- The difference between the corresponding figures in the numbers does not exceed 1.
Your task is to find how many such numbers are similar to this phone number. Since the answer can be very large, print it modulo \(10^9+7\).
Input format
- The first line indicates two space-separated numbers \(N, K\).
- The next line contains \(N\) digits.
Output format
Print one number denoting the answer modulo \(10^9+7\).
Constraints
\(1 ⩽ N ⩽ 10^4\)
\(1 ⩽ K ⩽ 100\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
63 votes
Tags:
Dynamic ProgrammingEasyOpenTwo dimensional
Points:30
80 votes
Tags:
CombinatoricsData StructuresDynamic ProgrammingEasyTwo dimensional
Points:30
22 votes
Tags:
AlgorithmsDynamic Programming2D dynamic programmingC++
Editorial