洛谷P3146 [USACO16OPEN]248
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.
输入输出样例
4
1
1
1
2
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 合并的最大值
可以由f[i][k],f[k+1][j]转移过来,转移条件为f[i][k]==f[k+1][j]
*/
#include<iostream>
#include<cstdio>
using namespace std;
#define maxn 300
int n,a[maxn],f[maxn][maxn],ans;
int main(){
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
f[i][i]=a[i];
}
for(int len=;len<=n;len++){
for(int l=;l+len-<=n;l++){
int r=l+len-;
for(int k=l;k<=r;k++){
if(f[l][k]==f[k+][r]){
f[l][r]=max(max(f[k+][r]+,f[l][k]+),f[l][r]);
ans=max(ans,f[l][r]);
}
}
}
}
cout<<ans;
}
洛谷P3146 [USACO16OPEN]248的更多相关文章
- 洛谷 P3146 [USACO16OPEN]248
P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- P3146 [USACO16OPEN]248
P3146 [USACO16OPEN]248 题解 第一道自己码出的区间DP快庆祝一哈 2048 每次可以合并任意相邻的两个数字,得到的不是翻倍而是+1 dp[L][R] 区间 L~R 合并结果 然后 ...
- 洛谷 P3146 248 题解
https://www.luogu.org/problemnew/show/P3146 区间dp,这次设计的状态和一般的有一定的差异. 这次我们定义$dp[i][j]$表示$[i,j]$的可以合并出来 ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 解题报告
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...
- 洛谷 P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题解
P3143 [USACO16OPEN]钻石收藏家Diamond Collector 题目描述 Bessie the cow, always a fan of shiny objects, has ta ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- 洛谷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 ...
- 洛谷 P3144 [USACO16OPEN]关闭农场Closing the Farm_Silver
传送门 题目大意: n个谷仓 ,每次关闭一个谷仓,问剩下没被关闭的谷仓是 否联通. 题解:并查集+倒序处理 代码: #include<iostream> #include<cstdi ...
随机推荐
- Wrong Answer,Memory Limit Exceeded
错误原因: 1.在递归的时候,递归函数中忘记加返回return. 1.1做题时遇到一个奇葩错误,把它记到这里,看代码: 代码1:错误,用c++提交wrong answer,但是用g++提交却accep ...
- POJ 3349 Snowflake Snow Snowflakes(哈希表)
题意:判断有没有两朵相同的雪花.每朵雪花有六瓣,比较花瓣长度的方法看是否是一样的,如果对应的arms有相同的长度说明是一样的.给出n朵,只要有两朵是一样的就输出有Twin snowflakes fou ...
- npm-install once
Once 是我最习惯的模块,它展示了几乎所有的我书写的通过issac Schlueter创建的应用. 原理很简单,Once使用各类一个函数且返回了一个函数,你可以调用这个函数,但是只能调用一次.如果你 ...
- mysql基本语句1
操作MySQL数据库 向表中插入数据 insert 语句可以用来将一行或多行数据插到数据库表中, 使用的一般形式如下: insert [into] 表名 [(列名1, 列名2, 列名3, ...)] ...
- json-lib的一些过滤操作
package demo4; import java.io.Serializable; import net.sf.json.JSONString; public class User impleme ...
- 关于MFC主菜单和右键弹出菜单
一.主菜单.弹出菜单和右键菜单的概念: 主菜单是窗口顶部的菜单,一个窗口或对话框只能有一个主菜单,但是主菜单可以被更改(SetMenu()更改): 创建方式:CMenu::CreateMenu(voi ...
- Agc011_C Squared Graph
传送门 题目大意 给定$n$个点$m$条边的简单图(无重边无自环),将有序点对$\{a,b\}$作为新的点,新产生的$n^2$个点中对于两个点,$\{a,b\},\{x,y\}$,当且仅当原图中存在边 ...
- bzoj1208Splay
Splay查前驱后继 小tips:在bzoj上while(scanf)这种东西可以让程序多组数据一起跑 反正没加我就t了 #include<cstdio> #include<iost ...
- ACM学习历程—广东工业大学2016校赛决赛-网络赛D 二叉树的中序遍历(数据结构)
题目链接:http://gdutcode.sinaapp.com/problem.php?cid=1031&pid=3 这算是一个胡搞类型的题目.当然肯定是有其数据结构支撑的. 唯一的限制就是 ...
- CentOS 7关闭firewalld启用iptables
在CentOS7中,有很多CentOS 6中的常用服务发生了变化. 其中iptables是其中比较大的一个.防火墙iptables被firewalld取代. 本文将介绍,如果采用systemctl关闭 ...