#P1388. 算式

    ID: 383 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp搜索福建省历届夏令营

算式

Description

Given nn numbers, without changing their relative order, insert kk multiplication signs and (nk1)(n-k-1) plus signs between them. Parentheses can be added arbitrarily to maximize the final result. Since the total number of operators is n1n-1, there is exactly one operator between every pair of adjacent numbers. For example:

When n=5n=5, k=2k=2, and the 55 numbers are 11, 22, 33, 44, 55, you can form:

1×2×(3+4+5)=241\times 2\times(3+4+5)=24 1×(2+3)×(4+5)=451\times(2+3)\times(4+5)=45 (1×2+3)×(4+5)=45(1\times2+3)\times(4+5)=45 \ldots\ldots

Input Format

The first line contains two integers separated by a space, denoting nn and kk.

The second line contains nn space-separated integers aia_i, representing the given numbers.

Output Format

Output a single line containing one integer, the maximum possible result.

5 2
1 2 3 4 5

120

Hint

Constraints

  • For 100%100\% of the testdata, it is guaranteed that 2n152\le n\le15, 0k<n0\le k\lt n, 0ai90 \leq a_i \leq 9, and the answer is less than 2312^{31}.

Translated by ChatGPT 5