P3146 [USACO16OPEN]248

题目描述

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 NN positive integers (2 \leq N\leq 2482≤N≤248), each in the range 1 \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,每次可以合并相邻两个,问最大能合出多少

输入输出格式

输入格式:

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

of NN 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之间的最大值。

吐槽:加强版戳这里

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 300
using namespace std;
int n,ans;
int f[MAXN][MAXN];
int main(){scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&f[i][i]);ans=max(ans,f[i][i]);}for(int i=n-1;i>=1;i--)for(int j=i+1;j<=n;j++){for(int k=i;k<j;k++)if(f[i][k]==f[k+1][j])f[i][j]=max(f[i][j],f[i][k]+1);ans=max(ans,f[i][j]);}cout<<ans;
}

转载于:https://www.cnblogs.com/cangT-Tlan/p/7603797.html

洛谷 P3146 [USACO16OPEN]248相关推荐

  1. P3146 [USACO16OPEN]248 G(python3实现)

    [USACO16OPEN]248 G - 洛谷 """P3146 [USACO16OPEN]248 G(python3实现) https://www.luogu.com. ...

  2. 洛谷P3144 [USACO16OPEN]关闭农场Closing the Farm_Silver

    洛谷P3144 [USACO16OPEN]关闭农场Closing the Farm_Silver 题目描述 FJ和他的奶牛们正在计划离开小镇做一次长的旅行,同时FJ想临时地关掉他的农场以节省一些金钱. ...

  3. P3146 [USACO16OPEN]248 P3147 [USACO16OPEN]262144

    注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...

  4. 洛谷P3146 区间dp做题笔记

    不是题解,不是题解,不是题解,纯属个人笔记,不知所言. 传送门:P3146 问:什么时候才能写的一手漂亮的dp? 答:夜深人静之时,魂归故里之日. 此题是一道基础的区间dp的题,看完题解犹豫片刻,之后 ...

  5. 洛谷P4319 变化的道路

    题意:给定图,每条边都有一段存在时间.求每段时间的最小生成树. 解:动态MST什么毒瘤...洛谷上还是蓝题... 线段树分治 + lct维护最小生成树. 对时间开线段树,每条边的存在时间在上面会对应到 ...

  6. 洛谷日报 2020年3月前索引

    2020 2019 2018 感觉洛谷日报全是干货!!!先记下来再说 2020 年洛谷日报索引 3 月 #260[dove]Church 编码(和 Lambda 演算) https://www.luo ...

  7. 洛谷日报索引(2020、2019、2018)

    历年洛谷日报索引 2020 2019 2018 感觉洛谷日报全是干货!!!先记下来再说 2020 年洛谷日报索引 3 月 #260[dove]Church 编码(和 Lambda 演算) https: ...

  8. 【洛谷P2615】神奇的幻方

    作者:letianJOE 题目链接 目录 题目描述 输入格式 输出格式 样例#1 样例输入 #1 样例输出 #1 样例#2 样例输入 #2 样例输出 #2(需要用宽屏来看) 提示 题目思路 样例模拟 ...

  9. 洛谷-题解 P2672 【推销员】

    独门思路!链表加优先队列! 这题一望,贪心是跑不掉了,但是我贪心并不好,所以想到了一个复杂一些但思路更保稳的做法 思路: 1 因为是离线操作,所以我们可以倒着求,先求x=n的情况,因为那样直接就知道了 ...

最新文章

  1. 快速人体姿态估计--Pose Proposal Networks
  2. HDF5数据处理(一)python
  3. 明天要上班了,假如上天再给我一个假期…
  4. vue点击按钮切换显示不同内容_邂逅Vue
  5. oracle计算最大与最小之间数,oracle 分析函数
  6. .NET Core 3.0 Preview 6 发布,新增用于 ARM64 的 Alpine Docker 镜像
  7. MVC:感觉用户认证标识(IsAuthenticated)有点延时。
  8. 开源公司黄页之阿里巴巴开源软件推荐(二)
  9. centos内存压力测试软件,教你在CentOS下的CPU、内存、IO、网络的压力测试工具与方法...
  10. java自动化键盘组合键_SELENIUM自动化模拟键盘快捷键操作实现解析
  11. C语言的酒店客房管理系统
  12. 计算机键盘复制键是哪个,键盘按什么键复制粘贴_键盘上复制粘贴快捷键是哪个键-win7之家...
  13. 电子工程师的自我修养 - 恒流源电路分析
  14. 手游SDK-数据上报
  15. 使用Certbot配置SSL证书【ubuntu系统】
  16. 计算机无法搜索到打印机驱动,电脑连接打印机需要装什么驱动(电脑搜不到打印机设备)...
  17. 一种新兴计数方式-视觉计数
  18. P1395 会议 题解
  19. POI列子:替换文本框值
  20. ora-00119和ora-00132问题的解决方法

热门文章

  1. python收集数据程序_用一行Python代码进行数据收集探索!Python真牛逼!
  2. 关于select中fd_set变量的一些通俗宏解释
  3. Python3实现32位整数翻转
  4. Oracle为什么装在XP系统,重装xp系统后oracle恢复方法
  5. python逐行写入excel_快来看看Python如何玩转Excel
  6. 西交计算机专业912一样吗,西安交大912(总分404 专业课133分)经验总结
  7. Pcm设备2M通道,E1的基础知识介绍
  8. 常见光纤收发器组网方式介绍
  9. PDH光端机常见故障问题解决方法
  10. 【渝粤教育】国家开放大学2019年春季 2732土地利用规划 参考试题