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. 2018 百度之星 初赛 第六题 HDU6349

    三原色图  Accepts: 281  Submissions: 1261  Time Limit: 1500/1000 MS (Java/Others)  Memory Limit: 262144/ ...

  2. vmware下centos6.7网络配置

    使用NAT方式: 查看/etc/sysconfig/network-script/ 下面没有ifcfg-eth0 新建ifcfg-eth0,内容如下 DEVICE=eth0 BOOTPROTO=dhc ...

  3. N+6 裁员裁出幸福感的背后

    01. 史上最牛逼的数据库公司,Oracle 裁员了. 2019年5月7日,甲骨文召开了面向全中国区的电话会议,亚太区人力资源负责人在会上简要介绍道,公司正进行业务结构调整,导致一部分人要离开岗位,这 ...

  4. QT窗体间传值总结之Signal&Slot

    在写程序时,难免会碰到多窗体之间进行传值的问题.依照自己的理解,我把多窗体传值的可以使用的方法归纳如下: 1.使用QT中的Signal&Slot机制进行传值: 2.使用全局变量: 3.使用pu ...

  5. 【Nginx】负载均衡

    本文介绍的负载均衡是针对的客户端请求在多个Nginx进程之间的均衡.注意与客户端请求在多个后端服务器之间的均衡相区别. 负载均衡问题的产生 在nginx中,建立连接的时候,会设计负载均衡问题.在多个子 ...

  6. Jekyll 搭建

    Jekyll搭建个人主页 早上昨晚上弄hexo的时候就开始有问题,发现命令有错误!今天早上来就开始把另外建立了仓库,转Jekyll,并不顺利,做了一天了,基本的theme的本地和远端主页可以显示,但当 ...

  7. Linux 快照

    10个方法助你轻松完成Linux系统恢复 提交 我的留言 加载中 已留言 这也就是为什么系统恢复功能会让人感觉如此神奇.你可以很快地重新回到工作中去,就像什么事情都没有发生一样,也不用去管造成系统故障 ...

  8. android POI搜索,附近搜索,周边搜索定位介绍

    POI搜索有三种方式.依据范围和检索词发起范围检索poiSearchInbounds.城市poi检索poiSearchInCity,周边检索poiSearchNearBy. 下以周边检索为例介绍怎样进 ...

  9. Swift简单介绍 教程

     Swift是什么? Swift是苹果于WWDC 2014公布的编程语言.这里引用The Swift Programming Language的原话: Swift is a new programmi ...

  10. JS表格分页组件:fupage的设计思路和详细使用方法(未来考虑开源,争取在2015年)

    一.背景         之前在秒针工作的时候,某js高级project师写了非常多自己的组件.当中一套是分页组件.叫做st-grid. 只是在我看来,bug太多.我常常给他反馈bug,我也不清楚为啥 ...