아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Double Up

면접 대비

시간 제한3초메모리 제한1024 MB

요약
2의 거듭제곱으로 이루어진 수열에서 원소를 지우거나 같은 인접 원소를 합쳐 하나만 남길 때 얻을 수 있는 가장 큰 값을 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 구간, 조합론
정답자
아직 제출이 없습니다

문제

A Double Up game consists of a sequence of nn numbers a_1,…,a_na\_1, \ldots, a\_n, where each a_ia\_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?

입력

The input consists of two lines. The first line contains nn (1≤n≤10001 \leq n \leq 1000). The second line contains numbers a_1,…,a_na\_1, \ldots, a\_n, where 1≤a_i≤21001\leq a\_i\leq 2^{100} for each ii.

출력

The ouput consists of a single line containing the largest number that can be obtained from the input sequence a_1,…,a_na\_1, \ldots, a\_n.

예제1

  1. 예제 1

    입력
    5
    4 2 2 1 8
    
    예상 출력
    16