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. SRM 146 DIV1 800

    Problem Statement      The purpose of a roundabout is to control the flow of traffic at a busy inter ...

  2. c++ 11 sleep()

    #include<chrono>#include<thread> std::this_thread::sleep_for(std::chrono::milliseconds(1 ...

  3. Linux课程实践一:Linux基础实践(SSH)

    一.SSH服务 1. 安装SSH (1)查看是否已经安装过ssh服务 rpm -qa |grep ssh (2)进行安装 sudo apt-get install openssh-server Ubu ...

  4. C3属性的轮播图(持续更新)

    天气好冷,都不想写代码.就先写个没有焦点的轮播图,过两天在补全. 用的是CSS3的属性 过渡transition 和 转换 transfrom:translateX() 只做了轮播和 鼠标进入停止轮播 ...

  5. C++函数重载和函数模板

    1.函数重载 这是小菜鸟写的一个例子. 函数重载应该注意以下几点: 1.1重载函数有类似的功能: 1.2只能以参数的类型(形参个数和类型)来重载函数, int max(int a,int b);flo ...

  6. Android之数据库的创建

    一.SQLite介绍 SQLite 一个非常流行的嵌入式数据库,它支持 SQL 语言,并且只利用很少的内存就有很好的性能.此外它还是开源的,任何人都可以使用它.许多开源项目((Mozilla, PHP ...

  7. Activity之间传递参数(一)

    -------siwuxie095 传递简单数据 (1)首先创建一个项目:SendArgs (2)选择API:21 Android 5.0 (3)选择 Empty Activity (4)默认 (5) ...

  8. Java(多态)动手动脑

    1> 请看以下"变态"的类(参看示例ParentChildTest.java) 上述代码的特点是: 子类和父类定义了一模一样的字段和方法 运行以下测试代码 1. 上边的程序运 ...

  9. JS产生随机数

    <script>   function GetRandomNum(Min,Max){   var Range = Max - Min;   var Rand = Math.random() ...

  10. mysql 上传数据到指定字段

    新建表prizecode,字段为code varchar(45) not null , usedAt TIMESTAMP;数据存放在 E:\prizecode\ 目录下,下面是上传语句 LOAD DA ...