• edited by
1,851 views
1 1 vote
A certain string-processing language offers a primitive operation which splits a string into two pieces. Since this operation involves copying the original string, it takes $n$ units of time for a string of length $n$, regardless of the location of the cut.
Suppose, now, that you want to break a string into many pieces. The order in which the breaks are made can affect the total running time. For example, if you want to cut a $20$-character string at positions $3$ and $10$, then making the first cut at position $3$ incurs a total cost of $20 + 17 = 37$, while doing position $10$ first has a better cost of $20 + 10 = 30$.
Give a dynamic programming algorithm that, given the locations of $m$ cuts in a string of length $n$, finds the minimum cost of breaking the string into $m + 1$ pieces. You may assume that all m locations are in the interior of the string so each split is non-trivial.

Please log in or register to answer this question.

Position:
Show:

Related questions

7 7 votes
1 answers 1 answer
1.9k
1.9k views
go_editor asked May 27, 2016
1,888 views
Given an undirected weighted graph $G = (V, E)$ with non-negative edge weights, we can compute a minimum cost spanning tree $T = (V, E')$. We can also compute, for a give...
12 12 votes
4 answers 4 answers
2.5k
2.5k views
go_editor asked May 27, 2016
2,507 views
Let $A$ be an array of $n$ integers, sorted so that $A \leq A \leq \dots A[n]$. Suppose you are given a number $x$ and you wish to find out if there exist indices $k$ a...
1 1 vote
1 1 answer
712
712 views
go_editor asked May 23, 2016
712 views
Given an undirected weighted graph $G = (V, E)$ with non-negative edge weights, we can compute a minimum cost spanning tree $T = (V, E')$. We can also compute, for a give...
5 5 votes
1 answers 1 answer
1.8k
1.8k views
go_editor asked May 23, 2016
1,798 views
Let $A$ be an array of $n$ integers, sorted, so that $A \leq A \leq \dots A[n]$. Suppose you are given a number $x$ and you wish to find out if there are indices $k$ an...