Digit strings

4.3

8 votes
Problem

You are given a string S of length N. You are also given an integer K. The string consists of digits from 19 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 109+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

1T51N1051K1018

Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

In first testcase, We have only one way to partition i.e 3,4,2,1,2.

In second testcase, we can partition in it two ways1,1 and 11

Editor Image

?