Minimize the sequence by putting appropriate operations ' DP'
Posted
by Vikas
on Stack Overflow
See other posts from Stack Overflow
or by Vikas
Published on 2010-05-16T15:49:57Z
Indexed on
2010/05/16
16:00 UTC
Read the original article
Hit count: 184
algorithm
|dynamic-programming
Given a sequence,say, 222 We have to put a '+' or '* ' between each adjacent pair. '* ' has higher precedence over '+'
We have to o/p the string whose evaluation leads to minimum value. O/p must be lexicographically smallest if there are more than one.
inp:222
o/p: 2*2+2
Explaination:
2+2+2=6
2+2*2=6
2*2+2=6
of this 3rd is lexicographically smallest.
I was wondering how to construct a DP solution for this.
© Stack Overflow or respective owner