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的更多相关文章

  1. 洛谷P3146 [USACO16OPEN]248

    P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...

  2. 洛谷 P3146 [USACO16OPEN]248

    P3146 [USACO16OPEN]248 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...

  3. P3146 [USACO16OPEN]248

    P3146 [USACO16OPEN]248 题解 第一道自己码出的区间DP快庆祝一哈 2048 每次可以合并任意相邻的两个数字,得到的不是翻倍而是+1 dp[L][R] 区间 L~R 合并结果 然后 ...

  4. [USACO16OPEN]248 G——区间dp

    [USACO16OPEN]248 G 题目描述 Bessie likes downloading games to play on her cell phone, even though she do ...

  5. 「区间DP」「洛谷PP3146 」[USACO16OPEN]248 G

    [USACO16OPEN]248 G 题目: 题目描述 Bessie likes downloading games to play on her cell phone, even though sh ...

  6. P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144

    注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...

  7. 又一道区间DP的题 -- P3146 [USACO16OPEN]248

    https://www.luogu.org/problemnew/show/P3146 一道区间dp的题,以区间长度为阶段; 但由于要处理相邻的问题,就变得有点麻烦; 最开始想了一个我知道有漏洞的方程 ...

  8. 【动态规划DP】[USACO16OPEN]248

    题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...

  9. [USACO16OPEN]248

    传送门啦 分析: 一个裸的区间dp,我们只需要注意合并的时候并不像2048那样加倍,每次都加1就好了 #include <iostream> #include <cstring> ...

随机推荐

  1. docker - apt-get更换国内源解决Dockerfile构建速度过慢

    背景 使用ubuntu镜像一般apt-get源地址都是在国外导致在构建时因为源地址问题导致下载速度极其得慢 在构建中应事先修改apt-get源地址来避免因下载速度过慢导致的构建缓慢问题 方案 在Doc ...

  2. SP1805 HISTOGRA - Largest Rectangle in a Histogram

    --------------------------------------------------- 我就是想学个单调栈然后全网都是个蓝题 ----------------------------- ...

  3. 破局AI落地难,数据标注行业需率先变革丨曼孚科技

    ​2019年,国内人工智能领域的投融资热情大幅降低,相当数量的AI企业彻底消失在了历史的长河中,“人工智能寒潮已至”甚至成为行业年度热词. 与前几年创业与投资热情齐头并进的盛况相比,近段时间的AI行业 ...

  4. Uva12169 扩展欧几里得模板

    Uva12169(扩展欧几里得) 题意: 已知 $x_i=(a*x_{i-1}+b) mod 10001$,且告诉你 $x_1,x_3.........x_{2t-1}$, 让你求出其偶数列 解法: ...

  5. 42.通过原生SQL语句进行操纵mysql数据库

    views.py文件中: from django.shortcuts import render # 导入connection模块 from django.db import connection d ...

  6. SpringBoot整合持久层技术--(一)JdbcTemplate

    简介: JdbcTemplate是Spring提供的一套JDBC模板框架,利用AOP技术解决直接使用JDBC带来的重复代码问题.它没有MyBatis使用那么灵活,但是却比直接使用JDBC方便得多.Sp ...

  7. Math, Date,JSON对象

    Math 对象 Math是 JavaScript 的原生对象,提供各种数学功能.该对象不是构造函数,不能生成实例,所有的属性和方法都必须在Math对象上调用. 静态属性 Math对象的静态属性,提供以 ...

  8. Java课后总结-原码、补码、反码

    1.原码.补码.反码的定义和表示方法. 数在计算机中是以二进制形式表示的. 数分为有符号数和无符号数. 原码.反码.补码都是有符号定点数的表示方法. 一个有符号定点数的最高位为符号位,0是正,1是副. ...

  9. idea插件不兼容问题

    https://plugins.jetbrains.com/ 找对应版本的插件

  10. MATLAB用“fitgmdist”函数拟合高斯混合模型(一维数据)

    MATLAB用“fitgmdist”函数拟合高斯混合模型(一维数据) 作者:凯鲁嘎吉 - 博客园 http://www.cnblogs.com/kailugaji/ 在MATLAB中“fitgmdis ...