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. cf732f

    思路:先缩点,再以最大连同分量为根dfs,代码太垃圾不想贴

  2. MongoDB释放磁盘空间

    1. 先删除旧的文档db.remove({}): 2. 从副本集中移除待清理的成员: (1) 登录副本集中的 Primary 服务器(/opt/mongo1/bin/mongo --port 2701 ...

  3. IIS发布项目 遇到的error

    HTTP 错误 403.14 - Forbidden Web 服务器被配置为不列出此目录的内容. 重新注册一下.net framework试试,当然这一步骤也可以排在第一位. 32位的Windows: ...

  4. ajax请求封装

    var xmlHttp; var ajaxRequest = function (params) { xmlHttp ={}; this.url = params.url; this.method = ...

  5. C# 获取excel架构并的导入sqlserver的方法

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. Activity之间传递参数(三)

    ------siwuxie095 传递值对象,即自定义的有数据类型的对象 1.首先 new 一个 class:User,用于创建自定义对象,同时右键 Generate 出 Constructor.se ...

  7. R语言画图,根据正负值画不同颜色,并且画水平线或者垂直线

    col=ifelse(x<0, "blue", "red") #如果x值为负值,用蓝色表示,反之,用红色表示 abline(v=0,col="g ...

  8. CSS控制文字,超出部分显示省略号

    http://www.daqianduan.com/6179.html <p style="width: 300px;overflow: hidden;white-space: now ...

  9. 第1周 支路变量、元件、KCL和KVL

    第1周的内容,介绍了: 电阻.独立源.受控元件等实体元器件, 电流.电压.功率等抽象名词, 端口.参考方向等分析时的概念工具, KCL.KVL两大分析定律, 解线性电路的普适方法----2B法. 引入 ...

  10. Hibernate 注解的用法以及说明(二)

    注解映射必须满足两大条件:Hibernate3.2以上版本和JSEE 5. @Entity 类注释,所有要持久化的类都要有@Entity   public class Org  implements ...