Tap here to switch tabs
Problem
Submissions

Problem: Construct String with Minimum Cost (Easy)

med
30 min
Try to solve the Construct String with Minimum Cost (Easy) problem.

Statement

You are given a string target, an array of strings words, and an integer array costs of the same length, where costs[i] represents the cost of using the string words[i].

Starting with an empty string, you can repeatedly append any string from words. Appending words[i] adds costs[i] to the total cost. You may select each string from words any number of times.

Return the minimum total cost required to construct target. If it is impossible to form target, return −1-1.

Constraints:

  • 1≤1 \leq target.length ≤2000\leq 2000

  • 1≤1 \leq words.length = costs.length ≤50\leq 50

  • 1≤1 \leq words[i].length ≤\leq target.length

  • target and words[i] consist only of lowercase English letters.

  • 1≤1 \leq costs[i] ≤105\leq 10^5

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Construct String with Minimum Cost (Easy)

med
30 min
Try to solve the Construct String with Minimum Cost (Easy) problem.

Statement

You are given a string target, an array of strings words, and an integer array costs of the same length, where costs[i] represents the cost of using the string words[i].

Starting with an empty string, you can repeatedly append any string from words. Appending words[i] adds costs[i] to the total cost. You may select each string from words any number of times.

Return the minimum total cost required to construct target. If it is impossible to form target, return −1-1.

Constraints:

  • 1≤1 \leq target.length ≤2000\leq 2000

  • 1≤1 \leq words.length = costs.length ≤50\leq 50

  • 1≤1 \leq words[i].length ≤\leq target.length

  • target and words[i] consist only of lowercase English letters.

  • 1≤1 \leq costs[i] ≤105\leq 10^5