题目描述

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=;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][j]=max(f[i][j],f[i][k]+);
ans=max(ans,f[i][j]);
}
cout<<ans;
}

洛谷 P3146 [USACO16OPEN]248的更多相关文章

  1. 洛谷P3146 [USACO16OPEN]248

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

  2. P3146 [USACO16OPEN]248

    P3146 [USACO16OPEN]248 题解 第一道自己码出的区间DP快庆祝一哈 2048 每次可以合并任意相邻的两个数字,得到的不是翻倍而是+1 dp[L][R] 区间 L~R 合并结果 然后 ...

  3. 洛谷 P3146 248 题解

    https://www.luogu.org/problemnew/show/P3146 区间dp,这次设计的状态和一般的有一定的差异. 这次我们定义$dp[i][j]$表示$[i,j]$的可以合并出来 ...

  4. 又一道区间DP的题 -- P3146 [USACO16OPEN]248

    https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...

  5. 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 解题报告

    P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...

  6. 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题解

    P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...

  7. P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144

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

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

    题目描述 Farmer John and his cows are planning to leave town for a long vacation, and so FJ wants to tem ...

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

    传送门 题目大意: n个谷仓 ,每次关闭一个谷仓,问剩下没被关闭的谷仓是 否联通. 题解:并查集+倒序处理 代码: #include<iostream> #include<cstdi ...

随机推荐

  1. 正式版的Linux Kernel 5.1来了,非LTS

    大神Linus Torvalds于今天发布了Linux Kernel 5.1内核正式版,在对现有功能进行改进的同时还带来了很多重要的改进.本次版本更新历时一个半月,不过值得注意的是它并非是长期支持版本 ...

  2. 使用iframe标签时如何通过jquery隐藏滚动条

    通过mouseover和mouseout事件来控制iframe的滚动条 代码如下:

  3. HTML5 基础测试题

          HTML5 基础测试题 1.HTML5 之前的 HTML 版本是什么?() A.HTML 4.01 B.HTML 4 C.HTML 4.1 D.HTML 4.9 2.HTML5 的正确 d ...

  4. Linux多线程实践(四 )线程的特定数据

    在单线程程序中.我们常常要用到"全局变量"以实现多个函数间共享数据, 然而在多线程环境下.因为数据空间是共享的.因此全局变量也为全部线程所共同拥有.但有时应用程序设计中有必要提供线 ...

  5. hadoop系列:zookeeper(2)——zookeeper核心原理(选举)

    1.前述 上篇文章<hadoop系列:zookeeper(1)--zookeeper单点和集群安装>(http://blog.csdn.net/yinwenjie/article/deta ...

  6. L2CAP数据发送和接收

    ACL 链路在 Bluetooth 中非常重要,一些重要的应用如 A2DP, 基于 RFCOMM 的应用.BNEP等都要建立 ACL 链路,发送/接收ACL 包.跟大家一起来分析 ACL 包发送/接收 ...

  7. zzulioj--1600--直线与圆(简单数学几何)

     1600: 直线与圆 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 360  Solved: 73 SubmitStatusWeb Board ...

  8. javascript系列-class6.String类型

    观察淘宝网商品数据   有一个东西叫服务器>>>>js的作用重要作用之一>>>>交互>>>>人机交互(事件)>>&g ...

  9. JTextArea 加入滚动条

    JTextArea texA; JScrollPane scroll; TextEdit(String name){ super(name); init(); } void init(){ this. ...

  10. WPF Template

    ControlTemplate ControlTemplate:用于定义控件的结构和外观,这样可以将控件外观与控件功能分离开. 在xaml中ControlTemplate通常配置到Style中,通过S ...