[UCSD白板题] Maximize the Value of an Arithmetic Expression

时间:2023-03-08 16:03:49
[UCSD白板题] Maximize the Value of an Arithmetic Expression

Problem Introduction

In the problem, your goal is to add parentheses to a given arithmetic expression to maximize its value.

Problem Description

Task.Find the maximum value of an arithmetic expression by specifying the order of applying its arithmetic operations using additional parentheses.

Input Format.The only line of the input contains a string \(s\) of length \(2n+1\) from some \(n\), with symbols \(s_0, s_1, \cdots, s_{2n}\). Each symbol at an even position of \(s\) is a digit(that is, an integer from 0 to 9) while each symbol at an odd position is one of three operations from \(\{+,-,*\}\).

Constraints.\(1 \leq n \leq 14\)(hence the string contains at most 29 symbols).

Output Format.Output the maximum possible value of the given arithmetic expression among different orders of applying arithmetic operations.

Sample 1.
Input:

1+5

Output:

6

Sample 2
Input:

5-8+7*4-8+9

Output:

200

Solution