1

Given a list of integers, insert the operations $( ) +$ and $*$ to yield the maximum value.

Examples: $2$ $1$ $1$ $2$ is maximized with $(2 + 1) * (2 + 1) = 9,$ and $1$ $1$ $1$ $1$ $1$ $1$ is maximized with $(1 + 1 + 1) * (1 + 1 + 1) = 9.$

Is there an algorithm that works every time to solve this problem?

Harsh Kumar
  • 2,846
user405476
  • 11
  • 1
  • Start with the product of all numbers > 1. If there are ones, replace smaller int by it+1. Continue until no more 1 free – pasaba por aqui Jan 09 '17 at 17:54
  • @RossMillikan: The links you include talks about partition of a single integer, in this problem the partitions are already fixed. If we have 4,1, then 2*3 is not a valid solution, even if 4+1=2+3. I do not think it is a duplicate of it. – pasaba por aqui Jan 09 '17 at 19:23
  • That is true, but as I said in the comment you just keep all the numbers 3 and above solo in the product. Then you group the $2$s and $1$s as the other questions say. – Ross Millikan Jan 09 '17 at 20:19

1 Answers1

1

First, we will proof an optimal constructive method, next proof that constructive methods gives the best solution.

a)

Let $a=a_0a_1a_2\cdots$ the optimal solution found until now (where $a_i$ can be an addition of numbers). Let $x=a_0$ and $y=a_1a_2\cdots$, $a=xy$.

Now, we must include number $z$ in the solution. It can be included as new factor $xyz$ or as an addition to one of the already existing ones $(x+z)y$. The inequality to consider is: $xyz \ge (x+z)y$

that concludes that:

if $z \ge 2$ then $xyz \ge (x+z)y$

if $z = 1$ then $xyz \lt (x+z)y$

in conclusion, new number must included multiplying all expression except if number is 1.

b) In case of new number equal to 1, add it to which existing factor?. The inequality is now:

$(x+1)y \ge x(y+1)$

with solution $y \ge x$, thus, add 1 to the smaller factor.

(initial case with $a=a_0$ is straightforward).

c) sequence to use in the constructive method.

Assume we must include two numbers $z_1$ and $z_2$. If both are greater than 1, the method will include both multiplying $a$, thus, same result if be include $z_1$ and next $z_2$ than if we include $z_2$ next $z_1$.

If both numbers are equal to one, obviously sequence is the same.

Finally, if we must include 1 and $z>1$, the sequences to consider are (assuming $x<y$ and $z<x$, $z<y$, remainder cases are straightforward):

$(x+1)yz \ge xy(z+1)$

with no solution, thus, include first $z$ next the 1.