Digit strings
Practice
4.3 (8 votes)
Algorithms
Dynamic programming
Problem
37% Success 1550 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code
You are given a string \(S\) of length \(N\). You are also given an integer \(K\). The string consists of digits from \(1-9\) only. Determine the number of ways to partition the string \(S\) such that each segment value is less than \(K\).
If there is no way to perform partition on the string, then print \(0\).
Since the answer could be a large, print the answer as \(10^9+7\).
Input format
- First line: of input contains a single integer T denoting the number of test cases.
- For each test case:
- First line: Two space-separated integers \(N\) and \(K\)
- Second line: A string \(S\) of size \(N\)
Output format
Print the required answer.
Constraints
\(1\le T\le 5\\ 1\le N\le 10^5\\ 1\le K\le 10^{18}\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
5 votes
Tags:
AlgorithmsDynamic ProgrammingMedium
Points:30
6 votes
Tags:
AlgorithmsDynamic ProgrammingMediumStacksString Manipulation
Points:30
12 votes
Tags:
Introduction to Dynamic Programming 1BitmaskDynamic ProgrammingAlgorithms
Editorial