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.
这道题由于我英语不好的原因让我卡在题意上了。。。。。
题意:给一串序列,如果相邻两个数相同就可以把他们变为一个比它们大一的数,如两个7可变为一个8;问题是我们要使最后的序列中的最大值尽可能的大,请输出这个最大的最大值。
题解:这个还是蛮好做的,用f[i][j]表示这段区间可转变成的最大的数字,同时用一个变量k把区间分为两段,若f[i][k]=f[k+1][j]就更新f[i][j],同时在更新过程中不断比较更新的值与最大值,若大于最大值,就储存下来。
具体程序:

#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n,j,ans,f[][],a[];
int main()
{
scanf("%d",&n);
for (int i=;i<=n;i++) cin>>a[i];
for (int i=;i<=n;i++) f[i][i]=a[i];
ans=;
for (int len=;len<=n;len++)
for (int i=;i<=n-len+;i++)
{
j=i+len-;
for (int k=i;k<=j-;k++)
if (f[i][k]==f[k+][j]) f[i][j]=max(f[i][j],f[k+][j]+);
if (f[i][j]>ans) ans=f[i][j];
}
printf("%d\n",ans);
return ;
}

4580: [Usaco2016 Open]248的更多相关文章

  1. BZOJ 4580: [Usaco2016 Open]248

    Description 一个序列,每次可以把相邻的两个数合为一个,价值+1,求最后的最大价值. Sol 区间DP. \(f[i][j]\) 表示 \(i-j\) 中合成一个数字为多少,转移就是枚举断点 ...

  2. bzoj4580: [Usaco2016 Open]248(区间dp)

    4580: [Usaco2016 Open]248 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 255  Solved: 204[Submit][S ...

  3. 【bzoj4580】[Usaco2016 Open]248 区间dp

    题目描述 Bessie likes downloading games to play on her cell phone, even though she does find the small t ...

  4. BZOJ4580: [Usaco2016 Open]248

    n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少. f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k ...

  5. BZOJ4580/Luogu3147 [Usaco2016 Open]248

    amazing #include <iostream> #include <cstdio> #include <cstring> #include <algo ...

  6. BZOJ 4576: [Usaco2016 Open]262144

    Description 一个序列,每次可以将两个相同的数合成一个数,价值+1,求最后最大价值 \(n \leqslant 262144\) Sol DP. 这道题是 BZOJ 4580: [Usaco ...

  7. bzoj AC倒序

    Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...

  8. bzoj Usaco补完计划(优先级 Gold>Silver>资格赛)

    听说KPM初二暑假就补完了啊%%% 先刷Gold再刷Silver(因为目测没那么多时间刷Silver,方便以后TJ2333(雾 按AC数降序刷 ---------------------------- ...

  9. 【BZOJ 4580】【Usaco2016 Open】248

    http://www.lydsy.com/JudgeOnline/problem.php?id=4580 区间dp,f(i,j)表示区间[i,j]全部合成一个数,这个数是多少. 可以归纳证明[i,j] ...

随机推荐

  1. Lucene 工作原理 之倒排索引

      1.简介 倒排索引源于实际应用中需要根据属性的值来查找记录.这种索引表中的每一项都包括一个属性值和具有该属性值的各记录的地址.由于不是由记录来确定属性值,而是由属性值来确定记录的位置,因而称为倒排 ...

  2. leetCode 354. Russian Doll Envelopes

    You have a number of envelopes with widths and heights given as a pair of integers (w, h). One envel ...

  3. MFC 不让程序显示在任务栏上

    如果是对话框程序直接在对话框的 初始化时,修改样式 ModifyStyleEx(WS_EX_APPWINDOW,WS_EX_TOOLWINDOW); 但是对于多文档或是单文档,则没有对应的对话框样式需 ...

  4. Xcode Pod使用

    安装pod  略.. 打开终端 cd  项目路径  (可以在xocde里项目右键show in Finder  讲工程目录拖入终端) 回车 vim podfile 回车 输入 :wq 保存 建立pod ...

  5. 主从LDAP

    yum -y install compat-openldap必须得安装这个   1:在主上       备份         cp /etc/openldap/slapd.conf /etc/open ...

  6. iOS 判断设备型号

    + (NSString*)deviceString { // 需要#import "sys/utsname.h" struct utsname systemInfo; uname( ...

  7. java中的 FileWriter类 和 FileReader类的一些基本用法

    1,FileWriter类(字符输出流类) |--用来写入字符文件的便捷类.此类的构造方法假定默认字符编码和默认字节缓冲区大小都是可接受的.要自己指定这些值,可以先在 FileOutputStream ...

  8. maven css/js 压缩配置

    <plugin>               <groupId>net.alchim31.maven</groupId>               <art ...

  9. java_js_json_日期格式化

    调用方法: var createBeginTime= createBeginTime.Format("yyyy-MM-dd 00:00:00"); 方法: Date.prototy ...

  10. notepad++的CoolFormat代码格式化插件使用

    因为notepad++的NppAStyle插件只支持格式化C.C++.C#.Java这四种编程语言的代码,所以本人推荐使用这个CoolFormat的插件,相比于NPPAStyle,CoolFormat ...