Imagine you're a cryptographer tasked with breaking down a secret message into beautiful segments. You have a string s consisting of digits '1' through '9', and you need to partition it into exactly k non-overlapping substrings following strict rules.
A partition is considered beautiful if:
- The string is divided into exactly
knon-intersecting substrings - Each substring has a length of at least
minLength - Each substring starts with a prime digit ('2', '3', '5', '7') and ends with a non-prime digit ('1', '4', '6', '8', '9')
Your mission: Count all possible beautiful partitions of the given string. Since the answer can be astronomically large, return it modulo 109 + 7.
Example: For string "23542" with k=2 and minLength=2, one beautiful partition could be ["235", "42"] - the first part starts with '2' (prime) and ends with '5' (prime), wait... that won't work! Let's try ["234", "52"] - first starts with '2' (prime) and ends with '4' (non-prime), second starts with '5' (prime) and ends with '2' (prime)... still wrong! This problem requires careful validation of each segment.
Input & Output
Constraints
- 1 β€ k β€ s.length β€ 200
- 1 β€ minLength β€ s.length
- s consists of digits '1' to '9'
- Prime digits are '2', '3', '5', '7'
- Answer is returned modulo 109 + 7