题目描述

Bessie likes downloading games to play on her cell phone, even though she doesfind the small touch screen rather cumbersome to use with her large hooves.

She is particularly intrigued by the current game she is playing.The game starts with a sequence of NNN positive integers (2≤N≤2482 \leq N\leq 2482≤N≤248), each in the range 1…401 \ldots 401…40. In one move, Bessie cantake two adjacent numbers with equal values and replace them a singlenumber of value one greater (e.g., she might replace two adjacent 7swith an 8). The goal is to maximize the value of the largest numberpresent in the sequence at the end of the game. Please help Bessiescore as highly as possible!

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

输入输出格式

输入格式:

The first line of input contains NNN, and the next NNN lines give the sequence

of NNN numbers at the start of the game.

输出格式:

Please output the largest integer Bessie can generate.

输入输出样例

输入样例#1:
复制

4
1
1
1
2
输出样例#1: 复制

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.


题解

一个还算朴素的区间dp。

设f[i][j]为从i到j全部合起来的最大值,枚举断点k,转移方程:

if(f[i][k]==f[k+][j])
f[i][j]=f[i][k]+;

然后注意一下for循环的嵌套顺序就星了。

 /*
qwerta
P3146 [USACO16OPEN]248
Accepted
100
代码 C++,0.5KB
提交时间 2018-09-18 16:19:46
耗时/内存
115ms, 1040KB
*/
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int f[][];
int main()
{
//freopen("a.in","r",stdin);
int n;
scanf("%d",&n);
for(int i=;i<=n;++i)
scanf("%d",&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][j]=f[i][k]+;
}
int ans=;
for(int i=;i<=n;++i)
for(int j=i;j<=n;++j)
ans=max(ans,f[i][j]);
cout<<ans;
return ;
}

「USACO16OPEN」「LuoguP3146」248(区间dp的更多相关文章

  1. 「kuangbin带你飞」专题二十二 区间DP

    layout: post title: 「kuangbin带你飞」专题二十二 区间DP author: "luowentaoaa" catalog: true tags: - ku ...

  2. 「bzoj1003」「ZJOI2006」物流运输 最短路+区间dp

    「bzoj1003」「ZJOI2006」物流运输---------------------------------------------------------------------------- ...

  3. 「CQOI2007」「BZOJ1260」涂色paint (区间dp

    1260: [CQOI2007]涂色paint Time Limit: 30 Sec  Memory Limit: 64 MBSubmit: 2057  Solved: 1267[Submit][St ...

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

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

  5. 「LuoguP1430」 序列取数(区间dp

    题目描述 给定一个长为n的整数序列(n<=1000),由A和B轮流取数(A先取).每个人可从序列的左端或右端取若干个数(至少一个),但不能两端都取.所有数都被取走后,两人分别统计所取数的和作为各 ...

  6. 「THUSC 2016」成绩单 & 方块消除 (区间dp)

    成绩单 $f[l][r][mi][mx]$表示从l到r发到还没发的部分的最小值为mi最大值为mx时的最小代价. $f[l][r][0][0]$表示从l到r全部发完的代价. 自己写的无脑dp,枚举中转点 ...

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

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

  8. bzoj4580: [Usaco2016 Open]248(区间dp)

    4580: [Usaco2016 Open]248 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 255  Solved: 204[Submit][S ...

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

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

随机推荐

  1. Mina、Netty、Twisted一起学(七):公布/订阅(Publish/Subscribe)

    消息传递有非常多种方式.请求/响应(Request/Reply)是最经常使用的.在前面的博文的样例中.非常多都是採用请求/响应的方式.当server接收到消息后,会马上write回写一条消息到clie ...

  2. java要在命令行执行eclipse的项目的方法

    在命令行运行eclipse的项目时须要把该项目生成一个能够运行的jar包,才干够在命令行下运行:分为两种情况,一种是项目中没有调用第三方的jar包,这样的比較简单.网上的资源也非常多,本文主要讲述第二 ...

  3. JavaWeb页面添加隐藏版权信息

    JavaWeb页面添加隐藏版权信息. 首先,我推荐一个值得玩味的版权站点,有兴趣的朋友能够去看上一看.Nazo Level 1,这个demo中我能发掘到有5个步骤,你看你能发现几层? 接下来.我来介绍 ...

  4. UDP用户数据报协议和IP分组

    UDP总体的封装格式例如以下: 以下是8字节UDP首部: 当IP层依据协议字段把UDP报文向上传送到UDP模块后,UDP模块再依据port号将数据发送到对应的进程中,以此实现进程到进程间的通信. 16 ...

  5. iOS 摇一摇的实现

    - (void)viewDidLoad { [super viewDidLoad]; [[UIApplication sharedApplication] setApplicationSupports ...

  6. Perl图书的一些体会

    近期,由于项目须要.又又一次将Perl学习起来. Perl老实说.让我又爱又恨. 爱它.是由于自己写代码的确非常爽. 是代码最少.速度最快的语言. 恨是由于看别人的代码实在太累了. 但,整体体会,在文 ...

  7. 《AndroidStudio有用指南》反馈问题和建议

    <AndroidStudio有用指南>反馈问题和建议 IntelliJ IDEA在持续更新, Android Studio也在持续更新, 本书也将会持续更新. Android Studio ...

  8. jsp页面中文乱码解决方案

    一.JSP页面中文乱码 在JSP页面中,中文显示乱码有两种情况:一种是HTML中的中文乱码,另一种是在JSP中动态输出的中文乱码. 先看一个JSP程序: <%@ page language=&q ...

  9. ElasticSearch(八)关于document的一些知识点

    先查看一条数据: GET /ecommerce/product/5 { "_index" : "ecommerce", "_type" : ...

  10. jQuery局部动态刷新

    AJAX 是与服务器交换数据的艺术,它在不重载全部页面的情况下,实现了对部分网页的更新. 在做项目的过程当中要用到jQuery动态刷新获取数据,上网查了一番教程,讲此知识点的教程很多,但个人感觉比较乱 ...