It’s from multidimensional DP:
Secret ravens from Winterfell started flying as the great war was coming. The Starks wrote the message using only 26 lowercase letters (‘a’- ‘z’) on pieces of paper and attached them to ravens. However the messages were intercepted in between by Lannisters who killed all the ravens. Each letter from a to z had a certain number associated with it. Now the lannisters wanted to cut the string of message in such a way that each letter shouldn’t appear in the string of length greater than the number associated with it. For example if the string is “aabca” and numbers associated with a b and c are 1 2 3 then ‘a’ cannot appear in a string of length more than 1 similarly ‘b’ in 2 and ‘c’ in 3. One possible way to cut this string is a | a | b | c | a or a | a | bc | a. Now the Lannisters asked you a question since they were weak at math. what are the minimum number of strings after cutting them satisfying the required constraints??
Input Format
first line consists of number n second line consists of string of length n third line consists of 26 integers denoting number associated with each character where first number corresponds to a and so on.
I don’t know how to approach the problem.