给你一个字符串 target、一个字符串数组 words 以及一个整数数组 costs,这两个数组长度相同。
设想一个空字符串 s。
你可以执行以下操作任意次数(包括 零 次):
[0, words.length - 1] 的索引 i。words[i] 追加到 s。costs[i]。返回使 s 等于 target 的 最小 成本。如果不可能,返回 -1。
示例 1:
输入: target = "abcdef", words = ["abdef","abc","d","def","ef"], costs = [100,1,1,10,5]
输出: 7
解释:
"abc" 追加到 s,得到 s = "abc"。"d" 追加到 s,得到 s = "abcd"。"ef" 追加到 s,得到 s = "abcdef"。示例 2:
输入: target = "aaaa", words = ["z","zz","zzz"], costs = [1,10,100]
输出: -1
解释:
无法使 s 等于 target,因此返回 -1。
提示:
1 <= target.length <= 5 * 1041 <= words.length == costs.length <= 5 * 1041 <= words[i].length <= target.lengthwords[i].length 的总和小于或等于 5 * 104target 和 words[i] 仅由小写英文字母组成。1 <= costs[i] <= 104