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. Spring mvc之SimpleUrlHandlerMapping

    1.配置文件如下 <bean id="method" class="com.xx.controller.xxxController" scope=&quo ...

  2. CSS制作简单图标

    CSS制作图标包括知识点如border-width.border-style.border-color.border-radius.对元素的定位拼接.旋转等结合起来. 图标效果如下(拖动滑块可缩放图标 ...

  3. 运行计划中cost计算方法

    概念: blevel:二元高度=索引高度-1 clustering_factor:集群因子,通过索引扫面得出的要查询table的blocks数量,clustering_factor接近table的bl ...

  4. 李洪强iOS开发之录音和播放实现

    李洪强iOS开发之录音和播放实现 //首先导入框架后,导入头文件.以下内容为托控件,在storyboard中拖出两个按钮为录音和播放按钮 //创建一个UIViewController在.h文件中写 # ...

  5. A + B Problem II(杭电1002)

    /*A + B Problem II Problem Description I have a very simple problem for you. Given two integers A an ...

  6. [LeetCode]Two Sum 【Vector全局指针的使用】

    无序数组返回两个元素和为给定值的下标. tricks:无序.返回下标增序.返回的是原始数组的下标. vector<int>*pa; bool cmp(int x,int y){ retur ...

  7. 小贝_mysql优化学习

    mysql优化 简要: 1.数据库设计优化 2.sql语句优化 3.表切割 4.读写分离技术 一.数据库设计优化 1.表设计要符合三范式.当然,有时也须要适当的逆范式 2.什么是三范式 一范式: 具有 ...

  8. BindException 无法指定被请求的地址

    Caused by: java.net.BindException: Problem binding to [hadoop3:8096] java.net.BindException: 无法指定被请求 ...

  9. jQuery 1.x and 2.x , which is better?

    1. jQuery 1.x和2.x的区别 或者可以说是jQuery 2.x有什么新特征? jQuery官方发布2.x原话 不再支持IE6/7/8,如果在IE9/10里只用“兼容性视图”模式也将会受到影 ...

  10. 什么是 XML Schema?

    XML Schema 的作用是定义 XML 文档的合法构建模块,类似 DTD. XML Schema: 定义可出现在文档中的元素 定义可出现在文档中的属性 定义哪个元素是子元素 定义子元素的次序 定义 ...