Help in a DP Problem

The question is as such

You are given string s1 = “” and a string s2 = “abcbcaa”
You can perform any one of the two operations on s1 :
Append a new character to s1. This costs you A dollars.
or
Append an existing substring of s1 to s1. This costs you B dollars.
Find the minimal dollars you need to pay in order to convert s1 to s2

This is not from any ongoing contest you can find it here
https://www.geeksforgeeks.org/teksystems-interview-experience-on-campus/ 
question1


@waqar_ahmad224  @everule1 Please help.

Does substring need to be continuous index. Like s1=“abcd” , Can “abd” be its substring?

Constraints?

I do not know…but lets keep it as string length is upto 10^5. means an O(n) time complexity solution.

Substring is always continuous only. So no abd is not a substring.