[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> ...
随机推荐
- 洛谷题解 P1024 【一元三次方程求解】
原题传送门 题目描述 有形如:ax^3+bx^2+cx^1+dx^0=0这样的一个一元三次方程.给出该方程中各项的系数(a,b,c,d均为实数),并约定该方程存在三个不同实根(根的范围在-100至10 ...
- Spring Cloud feign使用okhttp3
指南 maven <dependency> <groupId>io.github.openfeign</groupId> <artifactId>fei ...
- mongo操作图片储存
python 将图片存入mongodb,读取图片,gridfs模块原创A873054267 最后发布于2018-11-06 15:49:30 阅读数 2785 收藏展开导入图片引入模块,其中gridf ...
- 如何在 messager/alert/confirm等消息提示框中 获取 / 设置 嵌入 html内容中的 input[type=checkbox]等的选中状态?
总结, 有3点: 不能/不要 在 这些消息框 / 提示框/ 对话框中的 回调函数中去写代码: 获取嵌入 内容中input.checkbox的选中状态, 因为 虽然在这些框存在的时候, 这个 check ...
- ffmpeg rtp rtmp udp 推流命令
推组播 组播地址指的范围是224.0.0.0—239.255.255.255 ffmpeg -re -i chunwan.h264 -vcodec mpeg2video -f mpeg2video u ...
- 关于eclipse 项目导入不了 maven依赖的解决办法
1.首先确定你的项目是maven 项目 ,如果不是:项目右键Configure -->Convert to maven project. 2.在SVN导出的Maven项目,或以前不是用Maven ...
- vue 查看dist文件里的结构
场景:优化打包后的代码,提高性能. 1.方式一:report-json. 1.1 package.json文件里加入以下命令, "report": "vue-cli-se ...
- 2019-08-21 纪中NOIP模拟A组
T1 [JZOJ6315] 数字 题目描述
- VSCode常用插件之vscode-fileheader使用
更多VSCode插件使用请访问:VSCode常用插件汇总 vscode-fileheader这是一个给js文件(html.css也可以使用,但是没意义!!!)生成头部注释的插件,每次修改js文件之后会 ...
- 如何与GitHub同步,将本地文件push到到远程仓库
Run git config --global user.email "you@example.com" git config --global user.name "Y ...