/ WHOJ / 题库 /

[USACO16OPEN]248 G

[USACO16OPEN]248 G

题目描述

Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves.

She is particularly intrigued by the current game she is playing.The game starts with a sequence of \(N\) positive integers (\(2 \leq N\leq 248\)), each in the range \(1 \ldots 40\). In one move, Bessie cantake two adjacent numbers with equal values and replace them a singlenumber of value one greater (e.g., she might replace two adjacent \(7\)swith an \(8\)). The goal is to maximize the value of the largest numberpresent in the sequence at the end of the game. Please help Bessiescore as highly as possible!

Bessie 喜欢下载游戏在她的手机上玩,尽管她觉得小触摸屏与她的大蹄子配合使用相当麻烦。

她对目前正在玩的游戏特别感兴趣。游戏从 \(N\) 个正整数序列开始 (\(2≤N≤248\)),每个在 \(1…40\) 范围内。在一个动作中, Bessie 可以取两个值相等的相邻数字,并将其替换为值大一的单个数字(例如,她可能用 \(8\) 替换两个相邻的 \(7\))。目标是在游戏结束时使序列中出现的最大数字的值最大化。请尽可能多地帮助Bessie

格式

输入格式

The first line of input contains \(N\), and the next \(N\) lines give the sequence of \(N\) numbers at the start of the game.

第一行输入包含 \(N\),接下来的 \(N\) 行在游戏开始时给出了 \(N\) 个数字的序列。

输出格式

Please output the largest integer Bessie can generate.

请输出 Bessie 可以生成的最大整数。

样例1

样例输入1

4
1
1
1
2

样例输出1

3

样例解释

In this example shown here, Bessie first merges the second and third \(1\)s to obtain the sequence 1 2 2, and then she merges the \(2\)s into a \(3\). Note that it is not optimal to join the first two \(1\)s.

在此示例中,Bessie 首先合并第二个和第三个 \(1\) 以获得序列1 2 2,然后她将 \(2\) 合并为 \(3\)。请注意,将前两个 \(1\) 连接起来并不是最佳选择。