You are given a string to make and starting with the empty string, make it using appending and cloning cost Your task is to create the given target string. Starting with an string that is empty, you will have to add characters to it, until your string is the same as the one we want. You can either add a character to the end of you string with cost x, or you can clone you string with cost y. What we want is the cheapest way to do this.
Test Cases
targetString , appendcost, clonecost -&gt; totalcost

&quot;bb&quot;, 1, 2 -&gt; 2
&quot;bbbb&quot;, 2, 3 -&gt; 7
&quot;xzxpcxzxpy&quot;, 10, 11 -&gt; 71
&quot;abababab&quot;, 3, 5 -&gt; 16
&quot;abababab&quot;, 3, 11 -&gt; 23
Husk, 25 bytes

φ?ö▼z+:⁴∞²m⁰§:h§δf`€otṫḣ0


Try it online!

Inputs are in the order append cost, clone cost, target.

Explanation

φ?ö▼z+:⁴∞²m⁰§:h§δf`€otṫḣ0  Two explicit inputs and one implicit.
                           Example: 2, 3, s="abab"
φ                          Make a recursive function and call it on s:
 ?                      0   If s is empty, return 0.
  ö▼z+:⁴∞²m⁰§:h§δf`€otṫḣ    Otherwise do this.
                       ḣ    Prefixes: ["a","ab","aba","abab"]
                    otṫ     Suffixes except the first one: ["bab","ab","b"]
               §δf`€        Keep those prefixes that have the corresponding suffix as substring: ["ab","aba"]
            §:h             Prepend s minus last character: ["aba","ab","aba"]
          m⁰                Recurse on each: x=[6,4,6]
        ∞²                  Repeat the clone cost: [3,3,3,..
      :⁴                    Prepend append cost: [2,3,3,3,..
    z+                      Add component-wise to x: [8,7,9]
   ▼                        Minimum: 7