#P17372. [ECNA 2023] Double Up

    ID: 19790 远端评测题 2000ms 2048MiB 尝试: 0 已通过: 0 显示难度普及 上传者: 标签>动态规划 DP2023区间 DPICPC

[ECNA 2023] Double Up

Problem Description

A Double Up game consists of a sequence of nn numbers a1,,ana_1, \ldots, a_n, where each aia_i is a power of two. In one move one can either remove one of the numbers, or merge two identical adjacent numbers into a single number of twice the value. For example, for sequence 4,2,2,1,84,2,2,1,8, we can merge the 22s and obtain 4,4,1,84,4,1,8, then merge the 44s and obtain 8,1,88,1,8, then remove the 11, and, finally, merge the 88s, obtaining a single final number, 1616. We play the game until a single number remains. What is the largest number we can obtain?

Input Format

The input consists of two lines. The first line contains nn (1n10001 \leq n \leq 1000). The second line contains numbers a1,,ana_1, \ldots, a_n, where 1ai21001\leq a_i\leq 2^{100} for each ii.

Output Format

The output consists of a single line containing the largest number that can be obtained from the input sequence a1,,ana_1, \ldots, a_n.

5
4 2 2 1 8
16