bzoj4580: [Usaco2016 Open]248(区间dp)
4580: [Usaco2016 Open]248
Time Limit: 10 Sec Memory Limit: 128 MB
Submit: 255 Solved: 204
[Submit][Status][Discuss]
Description
Input
Output
Please output the largest integer Bessie can generate.
Sample Input
1
1
1
2
Sample Output
//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.
HINT
Source
/*
f[i][j]表示合并这段区间最大值
枚举中间点k,如果f[i][k]==f[k+1][j]且不等于0 就能转移。
*/
#include<bits/stdc++.h> #define N 250 using namespace std;
int n,ans,f[N][N]; 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][k]!=)
f[i][j]=max(f[i][j],f[i][k]+);
ans=max(ans,f[i][j]);
}
printf("%d",ans);
return ;
}
/*
题解里这个状态就比较神奇了。
f[i][j]表示到第i个数,得到数值为j,向右合并的最右端点。
方程f[i][j]=f[f[i][j-1]][j-1];类似倍增。
j比较小,因为两个合并之后得到的数只大1,所以可以跑过去。
*/
#include<bits/stdc++.h> #define N 270000 using namespace std;
int n,m,ans;
int f[N][],a[N];
int main()
{
freopen("ly.in","r",stdin);
scanf("%d",&n);
for (int i=; i<=n; i++)
{
scanf("%d",&a[i]);
f[i][a[i]]=i+;
}
for (int j=; j<=; j++)
for (int i=; i<=n; i++)
{
if (f[i][j]==) f[i][j]=f[f[i][j-]][j-];
if (f[i][j]>) ans=max(ans,j);
}
printf("%d\n",ans);
return ;
}
bzoj4580: [Usaco2016 Open]248(区间dp)的更多相关文章
- 【bzoj4580】[Usaco2016 Open]248 区间dp
题目描述 Bessie likes downloading games to play on her cell phone, even though she does find the small t ...
- BZOJ4580: [Usaco2016 Open]248
n<=248个数字,可以进行这样的操作:将相邻两个相同的数字合并成这个数字+1,求最大能合成多少. f(i,j)--区间i到j能合成的最大值,f(i,j)=max(f(i,k)+1),f(i,k ...
- P3146 [USACO16OPEN]248 (区间DP)
题目描述 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: 状态: ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- 【区间DP】【lgP3146】248
传送门 Description 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-40),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. In ...
- 「USACO16OPEN」「LuoguP3146」248(区间dp
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- 「区间DP」「洛谷PP3146 」[USACO16OPEN]248 G
[USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- 一道另类的区间dp题 -- P3147 [USACO16OPEN]262144
https://www.luogu.org/problemnew/show/P3147 此题与上一题完全一样,唯一不一样的就是数据范围; 上一题是248,而这一题是262144; 普通的区间dp表示状 ...
- 「USACO16OPEN」「LuoguP3147」262144(区间dp
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
随机推荐
- Intersection of Two Linked Lists(链表)
Write a program to find the node at which the intersection of two singly linked lists begins. For ex ...
- Eclipse中Maven运行项目时在Console中无日志出现的问题解决
这是由于工作空间损坏造成的,比如重装JDK后,或者重装Maven后这些问题.解决方法如下: 1.删除现有工作空间,重新选择一个新的. 2.重置Workspece. 3.可能是Maven版本太新导致的, ...
- google --SwitchyOmega and switchysharp ***
https://github.com/FelisCatus https://chrome.google.com/webstore/search/Proxy%20SwitchySharp%20?hl=z ...
- dtrace-debug
https://www.objc.io/issues/19-debugging/dtrace/
- 主成分分析(principal components analysis)
http://www.cnblogs.com/jerrylead/tag/Machine%20Learning/ PCA的思想是将n维特征映射到k维上(k<n),这k维是全新的正交特征.这k维特 ...
- Android sdcard读写权限问题之中的一个
博主在刚刚在学习过程中发现了一个关于android往sdcard读写的问题, 配置了该配置的提示无读写权限. 在AndroidManifest.xml文件里配置清单例如以下 <manifest ...
- Linux-百度云之AccleriderMini使用
打开命令行,然后输入: sudo apt-get install mono-devel 最后安装完成时,运行: 示例:mono xx.exe 实例:mono accleridaMini.exe 最后成 ...
- 用CSS画小猪佩奇,你就是下一个社会人! js将“I am a coder”反转成 “coder a am I”,不许用split,join,subString,reverse;求解方法三
用CSS画小猪佩奇,你就是下一个社会人! 欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 作者:江志耿 | 腾讯TEG网络工程师 我是佩奇,哼,这是我的弟弟乔治,呱呱,这是我的妈妈,嚯 ...
- MySQL存储结构的使用
前言 今天公司老大让我做一个MySQL的调研工作,是关于MySQL的存储结构的使用.这里我会通过3个样例来介绍一下MySQL中存储结构的使用过程,以及一些须要注意的点. 笔者环境 系统:Windows ...
- 在学习c++过程中,总结类的三个用户以及使用权限,感觉非常实用
首先我们需要知道类的三个用户分别是:类的实现者,类的普通用户和类的继承者(派生类),接下来分别讲解这几种用户的区别. 1 .类的实现者:顾明思议,就是类的设计者,拥有最大的权限,可以访问类中任何权限的 ...