题目描述

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. oralce中相关的概念整理

    [数据库名]  概念:就是一个数据库的标识,作用等同于我们的身份证的作用,假设一台机器上安装了多个数据库,那么每一个数据库都会有一个数据库名称相应,这些数据库名称在数据库被创建的时候,数据库名称也会被 ...

  2. Basic Vim Configuration

    原文: https://computers.tutsplus.com/tutorials/basic-vim-configuration--cms-21498 原来,vim的配置文件,.vimrc也是 ...

  3. [Algorithms] Quicksort algorithm using TypeScript

    Quicksort (also called partition sort and pivot sort) is arguably the most used sorting algorithm. I ...

  4. C# Http方式下载文件到本地

    下文代码是从网络(http://www.cnblogs.com/hayden/archive/2012/04/26/2472815.html)得来,亲测好用.我中修改了下格式和注释,版权属于原作者“舒 ...

  5. CSS3中的动画效果-------Day72

    还记得么,在前面也曾实现过"仅仅用css让div动起来",还记得当时是怎么实现的么,是的,transition,针对的也比較局限,仅仅有旋转角度啊,长宽啊之类的,所以说,与其说是动 ...

  6. Linux基础(4)-硬盘分区、格式化及文件系统的管理、软件包的管理、yum管理RPM包和python的源码安装

    一: 1)  开启Linux系统前添加一块大小为15G的SCSI硬盘 2)  开启系统,右击桌面,打开终端 3)  为新加的硬盘分区,一个主分区大小为5G,剩余空间给扩展分区,在扩展分区上划分1个逻辑 ...

  7. javascript 高级编程系列 - 创建对象

    1. 工厂模式 function createPerson(name, age) { var obj = {}; obj.name = name; obj.age = age; obj.getName ...

  8. FastDFS的配置、部署与API使用解读(7)Nginx的FastDFS模块(转)

    1.Nginx的FastDFS模块什么作用? 我们在使用FastDFS部署一个分布式文件系统的时候,通过FastDFS的客户端API来进行文件的上传.下载.删除等操作.同时通过 FastDFS的HTT ...

  9. ZOJ 1516 Uncle Tom&#39;s Inherited Land(二分匹配 最大匹配 匈牙利啊)

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=516 Your old uncle Tom inherited a p ...

  10. Cocos2d-x3.1FileUtilsTest使用

    Cocos2d-x3.1中FileUtils的使用:本使用教程是基于HelloWorld的.仅仅需在HelloWorld的init()函数中加入例如以下代码 //头文件 #include " ...