[USACO16OPEN]248&262144
Description
在1*n的序列中,每次可以合并两个相邻且相等的数,变成它们两个加1,求最大的数。
Solution
设\(f[i][j]\)表示\([i,k)\)这个区间能合并出\(j\)的最小的\(k\),\(f[i][j] = f[f[i][j-1]][j-1]\)。
Code
#include <cstdio>
const int N = 262144 + 10;
int n, f[N][60];
int main() {
scanf("%d", &n);
for (int i = 1, x; i <= n; ++i) scanf("%d", &x), f[i][x] = i+1;
int ans = 0;
for (int i = 2; i <= 58; ++i) {
for (int j = 1; j <= n; ++j) {
if (!f[j][i])
f[j][i] = f[f[j][i-1]][i-1];
if (f[j][i])
ans = i;
}
}
printf("%d\n", ans);
return 0;
}
[USACO16OPEN]248&262144的更多相关文章
- 洛谷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 题目描述 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 合并结果 然后 ...
- [USACO16OPEN]248 G——区间dp
[USACO16OPEN]248 G 题目描述 Bessie likes downloading games to play on her cell phone, even though she do ...
- 「区间DP」「洛谷PP3146 」[USACO16OPEN]248 G
[USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- 又一道区间DP的题 -- P3146 [USACO16OPEN]248
https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...
- 【动态规划DP】[USACO16OPEN]248
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- [USACO16OPEN]248
传送门啦 分析: 一个裸的区间dp,我们只需要注意合并的时候并不像2048那样加倍,每次都加1就好了 #include <iostream> #include <cstring> ...
随机推荐
- Linux下的python3,virtualenv,Mysql、nginx、redis等常用服务安装配置
Linux下的python3,virtualenv,Mysql.nginx.redis等常用服务安装配置 学了前面的Linux基础,想必童鞋们是不是更感兴趣了?接下来就学习常用服务部署吧! 安装环 ...
- Spring Boot源码(八):Spring AOP源码
关于spring aop的应用参见:Spring AOP-基于@AspectJ风格 spring在初始化容器时就会生成代理对象: 关于创建bean的源码参见:Spring Boot源码(六):Bean ...
- 将一个Head下的Line复制到另一个Head下(ef+linq)
今天工作中有一个需求,要求将一个Item下的Line复制到另外一个Item下面 这个需求在工作中很多,按照以往的经验肯定是先delete from,然后再一条条遍历后insert into 这两天正好 ...
- Wilson's Theorem
ProofsSuppose first that $p$ is composite. Then $p$ has a factor $d > 1$ that is less than or equ ...
- PP: Time series anomaly detection with variational autoencoders
Problem: unsupervised anomaly detection Model: VAE-reEncoder VAE with two encoders and one decoder. ...
- java网页程序采用 spring 防止 csrf 攻击 转
银行项目开发过程中,基本都会采用 spring 框架,所以完全可以不用自己开发 filter 去拦截 csrf 攻击的请求,而直接采用实现 spring 提供的 HandlerInterceptor ...
- Pikachu-XSS(跨站脚本)
XSS(跨站脚本)概述 Cross-Site Scripting 简称为“CSS”,为避免与前端叠成样式表的缩写"CSS"冲突,故又称XSS.一般XSS可以分为如下几种常见类型: ...
- html里面用Jquery移除tr元素后,滚动条会回到顶部问题处理
问题如下图,删除一行后,滚动条会自动回到顶部,即使先把滚动条禁止也还是会回到顶部 参考这个 https://bbs.csdn.net/topics/392233437 发现确实自己的按钮事件写在了a标 ...
- jQuery笔记(四)jQuery中的动画
jQuery最吸引人的地方莫过于能做出绚丽的动画了,也是能极大提高用户体验的地方,这次我们就来一探jQuery中的动画! 一. show()方法和hide()方法 show()方法与hide()方法是 ...
- Linux查看系统硬件信息命令
Linux查看系统硬件信息命令 查看磁盘类型(是否SSD) cat /sys/block/sda/queue/rotational code:0 SSD盘 code:1 SATA盘 查看物理CPU个数 ...