4580: [Usaco2016 Open]248

Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 255  Solved: 204
[Submit][Status][Discuss]

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!
给你n个数,每次可以将两个相邻的相同数x合并成x+1,求最大能合出多少
 

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

Gold 鸣谢duan2提供译文

/*
f[i][j]表示合并这段区间最大值
枚举中间点k,如果f[i][k]==f[k+1][j]且不等于0 就能转移。
*/
#include<bits/stdc++.h> #define N 250 using namespace std;
int n,ans,f[N][N]; int main()
{
scanf("%d",&n);
for (int i=; i<=n; i++)
{
scanf("%d",&f[i][i]);
ans=max(ans,f[i][i]);
}
for (int i=n-; i>=; i--)
for (int j=i+; j<=n; j++)
{
for (int k=i; k<j; k++)
if (f[i][k]==f[k+][j] && f[i][k]!=)
f[i][j]=max(f[i][j],f[i][k]+);
ans=max(ans,f[i][j]);
}
printf("%d",ans);
return ;
}
/*
题解里这个状态就比较神奇了。
f[i][j]表示到第i个数,得到数值为j,向右合并的最右端点。
方程f[i][j]=f[f[i][j-1]][j-1];类似倍增。
j比较小,因为两个合并之后得到的数只大1,所以可以跑过去。
*/
#include<bits/stdc++.h> #define N 270000 using namespace std;
int n,m,ans;
int f[N][],a[N];
int main()
{
freopen("ly.in","r",stdin);
scanf("%d",&n);
for (int i=; i<=n; i++)
{
scanf("%d",&a[i]);
f[i][a[i]]=i+;
}
for (int j=; j<=; j++)
for (int i=; i<=n; i++)
{
if (f[i][j]==) f[i][j]=f[f[i][j-]][j-];
if (f[i][j]>) ans=max(ans,j);
}
printf("%d\n",ans);
return ;
}

bzoj4580: [Usaco2016 Open]248(区间dp)的更多相关文章

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

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

  2. BZOJ4580: [Usaco2016 Open]248

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

  3. P3146 [USACO16OPEN]248 (区间DP)

    题目描述  给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: 状态: ...

  4. 又一道区间DP的题 -- P3146 [USACO16OPEN]248

    https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...

  5. 【区间DP】【lgP3146】248

    传送门 Description 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. In ...

  6. 「USACO16OPEN」「LuoguP3146」248(区间dp

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

  7. 「区间DP」「洛谷PP3146 」[USACO16OPEN]248 G

    [USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...

  8. 一道另类的区间dp题 -- P3147 [USACO16OPEN]262144

    https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状 ...

  9. 「USACO16OPEN」「LuoguP3147」262144(区间dp

    P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...

随机推荐

  1. 【微信小程序】开发实战 之 「开发框架MINA构成」

    小程序开发框架的目标是通过尽可能简单.高效的方式让开发者可以在微信中开发具有原生 APP 体验的服务. 微信团队为小程序提供的框架命名为MINA.MINA框架通过封装微信客户端提供的文件系统.网络通信 ...

  2. 【c++】c++一些基础面试题

    http://www.mianwww.com/html/2013/10/19128.html http://blog.csdn.net/wdzxl198/article/details/9050751 ...

  3. C#如何引用定义好的dll文件

    1 添加引用,找到dll文件   2 引用类的名称空间,生成类的实例,调用类的方法,测试OK.

  4. Material UI:很强大的CSS框架

    Material UI 是一款功能很强大,界面却十分清新简洁的CSS框架.Material UI利用了Google的Material Design 全新设计语言.而且让每个UI组件都变得很独立.因此开 ...

  5. 微信小程序之 Tabbar(底部选项卡)

    1.项目目录 2.在app.json里填写:tab个数范围2-5个 app.json { "pages": [ "pages/index/index", &qu ...

  6. hdu1507——Uncle Tom&#39;s Inherited Land*

    Uncle Tom's Inherited Land* Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  7. 李洪强iOS开发之性能优化技巧

    李洪强iOS开发之性能优化技巧 通过静态 Analyze 工具,以及运行时 Profile 工具分析性能瓶颈,并进行性能优化.结合本人在开发中遇到的问题,可以从以下几个方面进行性能优化. 一.view ...

  8. canvas鼠标点击划线

    今天学习了canvas,打算写一个鼠标划线的效果. <!DOCTYPE html> <html lang="en"> <head> <me ...

  9. Cts框架解析(6)-任务的运行

    前两篇讲了任务的加入和9大项配置,这篇讲任务的运行. 任务的运行 任务的运行在CommandScheduler的run方法中,所以删除全部的断点,在run方法中打上断点,重新启动启动debug: 先看 ...

  10. ClassLoader如何加载class

    jvm里有多个类加载,每个类加载可以负责加载特定位置的类, 例如: bootstrap类加载负责加载jre/lib/rt.jar中的类, 我们平时用的jdk中的类都位于rt.jar中. extclas ...