题目描述

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 NN positive integers (2 \leq N\leq 262,1442≤N≤262,144), each in the range 1 \ldots 401…40. In one move, Bessiecan take two adjacent numbers with equal values and replace them asingle number of value one greater (e.g., she might replace twoadjacent 7s with an 8). The goal is to maximize the value of thelargest number present in the sequence at the end of the game. Pleasehelp Bessie score as highly as possible!

Bessie喜欢在手机上下游戏玩(……),然而她蹄子太大,很难在小小的手机屏幕上面操作。

她被她最近玩的一款游戏迷住了,游戏一开始有n个正整数,(2<=n<=262144),范围在1-40。在一步中,贝西可以选相邻的两个相同的数,然后合并成一个比原来的大一的数(例如两个7合并成一个8),目标是使得最大的数最大,请帮助Bessie来求最大值。

输入输出格式

输入格式:

The first line of input contains NN, and the next NN lines give the sequence

of NN numbers at the start of the game.

输出格式:

Please output the largest integer Bessie can generate.

输入输出样例

输入样例#1: 复制

4
1
1
1
2
输出样例#1: 复制

3

说明

In this example shown here, Bessie first merges the second and third 1s to

obtain the sequence 1 2 2, and then she merges the 2s into a 3. Note that it is

not optimal to join the first two 1s.

一道非常有趣的dp

dp[i][j]表示从j开始合并没合并到i时的下表,由于合并必须是连续的一段区间

就可以用类似倍增更新一下是否可以合并出

#include<cstdio>
#include<algorithm>
#include<cstring>
inline int read() {
int x=;
char c=getchar();
while(c<''||c>'') c=getchar();
while(c<=''&&c>='')x=x*+c-'',c=getchar();
return x;
}
const int maxn = ;
int f[+][maxn];
int a[maxn];
int ans=;
int main() {
int n=read();
for(int i=;i<=n;++i) a[i]=read(),f[a[i]][i]=i+;
for(int i=;i<=;++i) {
for(int j=;j<=n;++j) {
f[i][j]=f[i][j]|f[i-][f[i-][j]];
if(f[i][j])ans=i;
}
}
printf("%d\n",ans);
return ;
}

最新文章

  1. PHP中的date()函数
  2. 玩转大麦盒子airplay
  3. jsp九大内置对象、四种作用域、跳转方式
  4. java网络编程,简单的客户端和服务器端
  5. [转]说说C#的async和await
  6. PB常用日期
  7. c# TextReader/TextWriter 的类
  8. Apache Shiro Architecture--官方文档
  9. 专家解读Linux操作系统内核中的GCC特性
  10. 动态加载JS过程中如何判断JS加载完成
  11. csharp中DateTime总结
  12. javaWeb项目带红色感叹号问题原因
  13. 用JS判断两个数字的大小
  14. Unity+NGUI打造网络图片异步加载和本地缓存工具(一)
  15. IAR 关于C++几个内存的使用及释放的问题
  16. json与csv的基础用与法
  17. javascript中的字符串对象
  18. Flask系列学习
  19. Git上传空文件夹的方法
  20. 5.String StringBuffer StringBuilder

热门文章

  1. redis配置密码 redis常用命令
  2. postgreysql
  3. Python 命令总结
  4. OpenStack之虚机热迁移代码解析
  5. leetcode 【 Find Minimum in Rotated Sorted Array 】python 实现
  6. Eclipse启动错误:A Java Runtime Environment(JRE) or Java Development Kit(JDK) must be available……
  7. Python-S9—Day86-ORM项目实战之会议室预定相关
  8. CSU-1980 不堪重负的树
  9. [python][django学习篇][6]操作数据库
  10. Struts2请求流程