[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 文件(持续更新)
一.文件类型 Linux操作系统把所有内容(文件.图片.视频.设备)都当作文件看待.处理,即一切皆文件. Linux系统把所有文件分为七种类型: 文件类型 文件类型标识 说明 使用ls -l命令查看文 ...
- aov.h-1.1
//AOV网与拓扑排序类 #ifndef _AOV_H_ #define _AOV_H_ #include<iostream> #include<cstdio> #includ ...
- C++ const和constexpr
const expression , 常量表达式 , 在<C++ Primer>的定义:值不会改变并且在编译过程就能得到计算结果的表达式. 它要求两点:值不会改变,编译过程得到结果. ...
- H5_0027:Layer使用
1,提示 document.getElementById("cloWd").onclick = function(){ layer.confirm('您确定要关 ...
- 使用VS中自带的一键打包功能将我们的ASP.NET Core类库打包并将程序包(类库)发布到NuGet平台上进行管理
本章将和大家简单分享下如何使用VS中自带的一键打包功能将我们的ASP.NET Core类库打包并将程序包(类库)发布到NuGet平台上进行管理. 一.注册并登录NuGet平台 NuGet官网:http ...
- 在eclipse中JS页面创建后<%@ page此处就马上就报错
修改路径:右键点击创建的jsp页面--->Build Path--->Configure Build Path---> Libraries--->Add Libraries-- ...
- WebApp开发-Zepto
zepto.js自己去官网下载哈. DOM操作 $(document).ready(function(){ var $cr = $("<div class='cr'>插入的div ...
- .net mvc 使用 aspose.cells导出数据
public class AsposeCellsHelper { public Workbook workBook; public Worksheet worksheet; Style style; ...
- centos系统mongodb安装
使用腾讯云搭服务器时,需要链接数据库,就从头开始重新安装了一遍mongodb,没想到这么麻烦,记得之前没这么麻烦. 1.下载mongodb(一篇博客的) 安装的是3.6版本 `` vim /etc/y ...
- 错误 CS8107 C# 7.0 中不支持功能“xxxxxx”。请使用 7.1 或更高的语言版本。
解决方法:项目右键属性 —> 生成 —> 找到最下面的高级按钮,点击高级按钮 —> 常规 —> 语言版本 —> 选择 C#最新次要版本,或者比当前版本更高的版本即可,点击 ...