Minimum Cost String Partition - Problem
Given a string s and a dictionary wordDict containing a list of valid words with their associated costs, partition the string into valid dictionary words such that the total cost is minimized.
Each word in the dictionary has a cost associated with it. Your task is to find the minimum cost to partition the entire string using words from the dictionary.
Example:
If s = "leetcode" and wordDict = {"leet": 10, "code": 15, "le": 5, "et": 8, "co": 12, "de": 7}, then one possible partition is ["leet", "code"] with cost 10 + 15 = 25. Another partition is ["le", "et", "co", "de"] with cost 5 + 8 + 12 + 7 = 32. The minimum cost partition would be the first one.
Return the minimum cost to partition the string, or -1 if it's impossible to partition the string using dictionary words.
Input & Output
Constraints
- 1 ≤ s.length ≤ 300
- 1 ≤ wordDict.length ≤ 1000
- 1 ≤ wordDict[i].length ≤ 20
- 1 ≤ wordDict[i].cost ≤ 1000
- All dictionary words are unique