洛谷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 ...
随机推荐
- PHP获取指定日期是星期几的实现方法
这篇文章主要介绍了PHP获取指定日期是星期几的实现方法,涉及php针对日期的读取.判断与字符串.数组相关运算操作技巧,需要的朋友可以参考下 本文实例讲述了PHP获取指定日期是星期几的实现方法.分享给大 ...
- 【Codeforces】Gym 101173B Bipartite Blanket 霍尔定理+状压DP
题意 给一张$n\times m$二分图,带点权,问有多少完美匹配子集满足权值和大于等于$t$ 这里有一个结论:对于二分图$\mathbb{A}$和$\mathbb{B}$集合,如果子集$A \in ...
- FileInputStream 把文件作为字节流进行读操作
//把文件作为字节流进行读操作 FileInputStream in = new FileInputStream(filename);//FileInputStream具体实现了在文件上读取数据
- codeforces 633A A. Ebony and Ivory(暴力)
A. Ebony and Ivory time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- MarkDown不支持图片放缩。。

Description It's Saturday today, what day is it after 11 + 22 + 33 + ... + NN days? Input There are ...
- 安装DCOS,关于docker异常引发的调查
入门DCOS,刚开始安装,碰到了一个异常: Bind for 0.0.0.0:9000 failed: port is already allocated. 调试这个问题花费了好长时间,因为无法通过n ...
- POJ1001(C++处理大数)
Exponentiation Time Limit: 500MS Memory Limit: 10000K Total Submissions: 158025 Accepted: 38470 ...
- 使用Sublime编写HTML页面时发现,虽然已经设置好了UTF-8的编码格式,但却发现HTML页面的汉字仍然是乱码。
相信有些同学在使用Sublime编写HTML页面时发现,虽然已经设置好了UTF-8的编码格式,但却发现HTML页面的汉字仍然是乱码吧.我今天就遇到了这样的问题. 第一步:重新设置一下你的meta,设置 ...
- SP:目录
ylbtech-SP:目录 商谱开发框架 1.返回顶部 1. 1.WebUIWeChatUI MobileUI 2.Core-Model-Repository-Security -Service3.D ...