luogu P3147 [USACO16OPEN]262144
题目描述
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 262,1442≤N≤262,144), each in the range 1 \ldots 401…40. In one move, Bessiecan take two adjacent numbers with equal values and replace them asingle number of value one greater (e.g., she might replace twoadjacent 7s with an 8). The goal is to maximize the value of thelargest number present in the sequence at the end of the game. Pleasehelp Bessie score as highly as possible!
Bessie喜欢在手机上下游戏玩(……),然而她蹄子太大,很难在小小的手机屏幕上面操作。
她被她最近玩的一款游戏迷住了,游戏一开始有n个正整数,(2<=n<=262144),范围在1-40。在一步中,贝西可以选相邻的两个相同的数,然后合并成一个比原来的大一的数(例如两个7合并成一个8),目标是使得最大的数最大,请帮助Bessie来求最大值。
输入输出格式
输入格式:
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.
输入输出样例
说明
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
dp[i][j]表示从j开始合并没合并到i时的下表,由于合并必须是连续的一段区间
就可以用类似倍增更新一下是否可以合并出
#include<cstdio>
#include<algorithm>
#include<cstring>
inline int read() {
int x=;
char c=getchar();
while(c<''||c>'') c=getchar();
while(c<=''&&c>='')x=x*+c-'',c=getchar();
return x;
}
const int maxn = ;
int f[+][maxn];
int a[maxn];
int ans=;
int main() {
int n=read();
for(int i=;i<=n;++i) a[i]=read(),f[a[i]][i]=i+;
for(int i=;i<=;++i) {
for(int j=;j<=n;++j) {
f[i][j]=f[i][j]|f[i-][f[i-][j]];
if(f[i][j])ans=i;
}
}
printf("%d\n",ans);
return ;
}
luogu P3147 [USACO16OPEN]262144的更多相关文章
- P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144一道非常有趣的游戏,不,题目.当数据水时,可以这样表示状态.f[i][j]表示合并[i,j]区间所能得到的最大值,有点floyed的小味道.if(f[ ...
- 洛谷P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
- 洛谷 P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
- 一道另类的区间dp题 -- P3147 [USACO16OPEN]262144
https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状 ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- 洛谷 P3147 [USACO16OPEN]262144 P
链接: P3147 P3146双倍经验 前言: 今天发现的一道很有意思的DP题 分析: 第一眼以为是区间DP,于是设f[i][j]为从第i个数到第j个数可以合出的最大值,但思考后发现并不能简单合并,并 ...
- P3147 [USACO16OPEN]262144 (贪心)
题目描述 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-262,144),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: ...
- [USACO16OPEN]262144
传送门啦 其实大家可以先看一下这个题 [USACO16OPEN]248 分析: 数据范围很奇特:n特别,a[i]特别——如果O(N^3)能接受就直接区间DP水过了,但是不行,于是考虑设计一个状态囊括a ...
- 【[USACO16OPEN]262144】
发现这个数列的范围特别大但是值域的范围特别小 于是可以大胆猜测这道题值域肯定需要开到状态里去 又发现\(262144=2^{18}\)这个暗示非常明显啊,暗示这道题跟二进制有关系 其实也没什么关系 设 ...
随机推荐
- c++实验5
设计并实现一个机器宠物类MachinePets #include <iostream> #include <string> using namespace std; class ...
- GBDT算法简述
提升决策树GBDT 梯度提升决策树算法是近年来被提及较多的一个算法,这主要得益于其算法的性能,以及该算法在各类数据挖掘以及机器学习比赛中的卓越表现,有很多人对GBDT算法进行了开源代码的开发,比较火的 ...
- Excel动画教程50例(一)
Excel动画教程50例(一) 1.自动筛选 2.在Excel中字符替换 3.在Excel中冻结行列标题 4.在Excel中为导入外部数据 5.在Excel中行列快速转换 6.共享Excel工作簿 7 ...
- lucene.NET详细使用与优化详解
lucene.NET详细使用与优化详解 http://www.cnblogs.com/qq4004229/archive/2010/05/21/1741025.html http://www.shan ...
- [oldboy-django][1初识django]创建虚拟(干净)的Python环境
如果应用A需要jinja 2.7,而应用B需要jinja 2.6怎么办?此时可以针对不同应用创建不同的虚拟环境. 这种情况下,每个应用可能需要各自拥有一套“独立”的Python运行环境.virtual ...
- 链表的问题,ListNode问题
算法面试,有关ListNode的问题 class ListNode{ ListNode *next; int val; ListNode(int x): val(x){}}; 在面试的时候,怎么快速想 ...
- Redhat/CentOS安装vsftp软件
1.更新yum源 首先需要更新系统的yum源,便捷工具下载地址:http://help.aliyun.com/manual?spm=0.0.0.0.zJ3dBU&helpId=1692 2.安 ...
- GDOI2018前夕 错误总结
算法易错点 $FFT$ 1.注意精度,以及是否取整 2.注意$complex$类不要写错,复数乘法是这样的: complex operator *(const complex &b){retu ...
- Manthan, Codefest 16 B 数学
B. A Trivial Problem time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- bzoj 合集 1079 1791 1876 2208 2306
1079 记忆化瞎搞吧,[a][b][c][d][e][l]表示当前有能涂1次的油漆a个,能涂2次的b个….前一个颜色为l,再搞下转移就行了. 1791 基环树上找直径 1876 高精度 2208 看 ...