p coins to append an arbitrary single letter to the back, or. q coins to copy a substring that has already been outputted and paste it in the back.Jerry now wants to write a letter to Tom. The letter is a string. S which contains only lowercase Latin letters. But as Jerry is not very wealthy, he wants to know the minimum number of coins he needs to write this letter.
One day, Jerry found a strange typewriter. This typewriter has 2 input modes: pay p p coins to append an arbitrary single letter to the back, or q q coins to copy a substring that has already been outputted and paste it in the back. Jerry now wants to write a letter to Tom. The letter is a string S S which contains only lowercase Latin letters. But as Jerry is not very wealthy, he wants to know the minimum number of coins he needs to write this letter.
(图片来源网络,侵删)