No.505 Card Expression 2
Problem Statement
$N$ cards, each with an integer from $-9 \ $ to $ \ 9$ written on it, are lined up in a row.
You want to form an expression by placing $1$ card with one of $+,-,×,÷$ written on it between each pair of adjacent integer cards. $($There are infinitely many cards of each kind.$)$
The operators have no precedence; the expression is evaluated from left to right.
Find the maximum possible value of the resulting expression.
[Handling of $÷$]
・Division by 0 is not allowed, so it must not be placed before a 0.
・If the division is not exact, the fractional part is truncated toward 0 $($ignored$)$.
Input
$N$ $a_1 \ a_2 \ ... \ a_N$
The $1$st line contains $N$.
The $2$nd line contains the integers written on the cards, separated by spaces.
$2 \le N \le 16$
$-9 \le a_i \le 9$
Output
Output the maximum value.
Sample
Sample 1
Input
4 0 -9 1 5
Output
50
$0 \ - \ (-9) \ + \ 1 \ × \ 5 \ = \ 50$
Sample 2
Input
8 6 6 1 3 3 2 2 -1
Output
1333
Sample 3
Input
16 6 9 1 2 1 2 1 2 1 4 1 4 1 8 1 2
Output
114514
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ixmel