String Partitioning
Practice
0 (0 votes)
Dynamic programming
Algorithms
Medium Hard
Problem
14% Success 176 Attempts 50 Points 3s Time Limit 256MB Memory 1024 KB Max Code
Given a large string of integers S of length N, divide the string into K non-empty substrings such that the sum of cost of each substring is minimised. The cost of a substring is \(\prod_{i = 0}^{9} (freq[i] + 1)\), where \(freq[i]\) denotes the number of occurrence of integer i in the substring under consideration.
Input
First line contains a single integer T denoting the number of test cases.
First line of each test case contains two integers N and K.
Second line of each test case contains the string S
Output
For each test case output the minimum cost.
Constraints
1 <= T <= 50
1 <= N <= 500
1 <= K <= N
0 <= S[i] <= 9
Submissions
Please login to view your submissions
Similar Problems
Points:50
2 votes
Tags:
Dynamic ProgrammingDigit DpAlgorithmsMedium-HardDigit DPAdvanced
Points:50
18 votes
Tags:
Dynamic ProgrammingMedium-Hard
Points:50
3 votes
Tags:
Dynamic ProgrammingAlgorithmsMedium-HardAdvanced
Editorial