Tap here to switch tabs
Problem
Submissions

Problem: Number of Beautiful Partitions

med
30 min
Try to solve the Number of Beautiful Partitions problem.

Statement

You are given a string s consisting of digits from '$1'$ to '$9'$, and two integers k and minLength.

A partition of s is called beautiful if:

  • s is divided into exactly k contiguous, non empty substrings.

  • Each substring has a length of at least minLength.

  • The first character of each substring is a prime digit ('$2'$, '$3'$, '$5'$, or '$7'$).

  • The last character of each substring is a non prime digit ('$1'$, '$4'$, '$6'$, '$8'$, or '$9'$).

Return the total number of beautiful partitions of s. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq k, minLength ≤\leq s.length ≤1000\leq 1000

  • s consists of the digits '$1'$ to '$9'$.

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Number of Beautiful Partitions

med
30 min
Try to solve the Number of Beautiful Partitions problem.

Statement

You are given a string s consisting of digits from '$1'$ to '$9'$, and two integers k and minLength.

A partition of s is called beautiful if:

  • s is divided into exactly k contiguous, non empty substrings.

  • Each substring has a length of at least minLength.

  • The first character of each substring is a prime digit ('$2'$, '$3'$, '$5'$, or '$7'$).

  • The last character of each substring is a non prime digit ('$1'$, '$4'$, '$6'$, '$8'$, or '$9'$).

Return the total number of beautiful partitions of s. Since the answer may be very large, return it modulo 109+710^9 + 7.

Constraints:

  • 1≤1 \leq k, minLength ≤\leq s.length ≤1000\leq 1000

  • s consists of the digits '$1'$ to '$9'$.