博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
bzoj4580: [Usaco2016 Open]248
阅读量:4668 次
发布时间:2019-06-09

本文共 1749 字,大约阅读时间需要 5 分钟。

bzoj4580: [Usaco2016 Open]248

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 23  Solved: 21
[][][]

Description

Bessie likes downloading games to play on her cell phone, even though she does find the small touch 
screen rather cumbersome to use with her large hooves.She is particularly intrigued by the current g
ame she is playing. The game starts with a sequence of NN positive integers (2≤N≤248), each in the
 range 1…40. In one move, Bessie can take two adjacent numbers with equal values and replace them a
 single number of value one greater (e.g., she might replace two adjacent 7s with an 8). The goal is
 to maximize the value of the largest number present in the sequence at the end of the game. Please 
help Bessie score as highly as possible!

 

Input

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

 

Output

Please output the largest integer Bessie can generate.

 

Sample Input

4
1
1
1
2

Sample Output

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.

HINT

 

Source

 

显然我们可以区间DP。。。

1 #include
2 #define rep(i,l,r) for(int i=l;i<=r;i++) 3 #define N 300 4 int n,ans,s[N],f[N][N],j; 5 using namespace std; 6 int main () { 7 scanf("%d",&n); rep(i,1,n) scanf("%d",&s[i]),ans=max(ans,s[i]); 8 rep(i,1,n) f[i][i]=s[i]; 9 rep(len,2,n) for(int i=1;i+len-1<=n;i++) {10 j=i+len-1;11 f[i][j]=-1;12 rep(k,i,j-1) if(f[i][k]==f[k+1][j]) f[i][j]=max(f[i][j],f[i][k]+1);13 ans=max(ans,f[i][j]);14 }15 cout<
View Code

 

转载于:https://www.cnblogs.com/Bloodline/p/5492959.html

你可能感兴趣的文章
Codeforces 1163A - Eating Soup
查看>>
vim使用小技巧
查看>>
AutoCAD ObjectARX和RealDWG的基本数据操作
查看>>
CSS的常见属性
查看>>
java ArrayList源码分析(转载)
查看>>
WIN10 64位 JDK的安装
查看>>
php : RBAC 基于角色的用户权限控制-表参考
查看>>
Hadoop入门经典:WordCount
查看>>
Reverse Words in a String
查看>>
在web浏览器上显示室内温度(nodeJs+arduino+socket.io)
查看>>
nodejs生成UID(唯一标识符)——node-uuid模块
查看>>
Java删除文件夹和文件
查看>>
CSU 1803 2016(数论)
查看>>
UVA116 单向 DSP(多段图最短路)
查看>>
Kruskal算法
查看>>
2018中国域名大会-强调服务与网络信息安全
查看>>
C#日常总结
查看>>
基于Lumisoft.NET组件开发碰到乱码等一些问题的解决
查看>>
SSH框架整合截图总结(三)
查看>>
初步了解Ajax
查看>>