[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> ...
随机推荐
- IO流学习之综合运用(文件复制)
通过File.字节流.字节流缓冲区实现文件复制 需求: 1.用File类读取指定文件File下的所有文件(包括Copy文件夹内的所有文件) 2.将所有文件复制到指定文件FileCopy夹下 需求分析: ...
- SpringBoot导出excel数据报错Could not find acceptable representation
转自:https://blog.csdn.net/mate_ge/article/details/93518286?utm_source=distribute.pc_relevant.none-tas ...
- 2-1.了解Pod对象
1.Pod参数定义 # 必填,版本号 apiVersion: string kind: Pod # 必填,元数据 metadata: # 必填,Pod对象的名称(命名规范需要符合RFC 1035规范) ...
- c++多线程编程互斥锁初步
上一次讲述了多线程编程,但是由于线程是共享内存空间和资源的,这就导致:在使用多线程的时候,对于共享资源的控制要做的很好.先上程序: #include <iostream> #include ...
- Jmeter实践
Jmeter时间戳函数 详见:https://blog.csdn.net/dreamtl/article/details/68957447 ${__timeShift(yyyy-MM-dd HH:mm ...
- AMCL论文及源码解析--参数(持续更新中)
整理内容来自:http://wiki.ros.org/amcl 1.AMCL订阅的节点: scan (sensor_msgs/LaserScan):激光数据 tf (tf/tfMessage):各种转 ...
- PP: Deep clustering based on a mixture of autoencoders
Problem: clustering A clustering network transforms the data into another space and then selects one ...
- matlab HW求法笔记
for i=1:9400 Sbox_out_11(i) = length(findstr(num2str(dec2bin(Sbox_out_1(i,:))),'1')); end
- ECMAScript规范中第六大基本类型 Symbol
初步了解第六大基本类型Symbol 概述: 什么是Symbol.Symbol是一个标记,一个独一无二的记号. Symbol的出现主要是解决了以前ES5中两个问题 在属性中同名的属性会被覆盖 无法做到属 ...
- jQuery---html方法和text方法
html方法和text方法 //html:innerHTML text:innerText console.log($("div").html());//<h3>我是标 ...