一道另类的区间dp题 -- P3147 [USACO16OPEN]262144
https://www.luogu.org/problemnew/show/P3147
此题与上一题完全一样,唯一不一样的就是数据范围;
上一题是248,而这一题是262144;
普通的区间dp表示状态表示法根本存不下,
这时我们就要想另外的状态表示法;
#include <bits/stdc++.h>
#define read read()
#define up(i,l,r) for(int i = (l);i <=(r); i++)
using namespace std;
int read
{
int x = ; char ch = getchar();
while(ch < || ch > ) ch = getchar();
while(ch >= && ch <= ) {x = * x + ch - ; ch = getchar();}
return x;
}
int n,f[][],ans;// 262144 -> 2 ^ 18 //所以最多 40 + 18 = 58;
//f[i][j]表示到第i个数,得到数值为j,向右合并的最右端点.(左闭右开 -> [,) )
int main()
{
freopen("262144.in","r",stdin);
n = read; up(i,,n) f[i][(read)] = i + ;
up(j,,)
up(i,,n)
{
if(f[i][j] == ) f[i][j] = f[f[i][j-]][j-];
if(f[i][j]) ans = j;//right : 包括上面的,f[i][j] > 0时才更新
//else ans = j; //-> false //容易写错
//f[i][j]大于0是关键;
}
printf("%d",ans);
return ;
}
一道另类的区间dp题 -- P3147 [USACO16OPEN]262144的更多相关文章
- P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144一道非常有趣的游戏,不,题目.当数据水时,可以这样表示状态.f[i][j]表示合并[i,j]区间所能得到的最大值,有点floyed的小味道.if(f[ ...
- 洛谷 P3147 [USACO16OPEN]262144 P
链接: P3147 P3146双倍经验 前言: 今天发现的一道很有意思的DP题 分析: 第一眼以为是区间DP,于是设f[i][j]为从第i个数到第j个数可以合出的最大值,但思考后发现并不能简单合并,并 ...
- 洛谷 P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
- 洛谷P3147 [USACO16OPEN]262144
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
- luogu P3147 [USACO16OPEN]262144
题目描述 Bessie likes downloading games to play on her cell phone, even though she doesfind the small to ...
- P3146 [USACO16OPEN]248 & P3147 [USACO16OPEN]262144
注:两道题目题意是一样的,但是数据范围不同,一个为弱化版,另一个为强化版. P3146传送门(弱化版) 思路: 区间动规,设 f [ i ][ j ] 表示在区间 i ~ j 中获得的最大值,与普通区 ...
- P3147 [USACO16OPEN]262144 (贪心)
题目描述 给定一个1*n的地图,在里面玩2048,每次可以合并相邻两个(数值范围1-262,144),问最大能合出多少.注意合并后的数值并非加倍而是+1,例如2与2合并后的数值为3. 这道题的思路: ...
- CodeForces - 1107E 区间DP
和紫书上的Blocks UVA - 10559几乎是同一道题,只不过是得分计算不同 不过看了半天紫书上的题才会的,当时理解不够深刻啊 不过这是一道很好区间DP题 细节看代码 #include<c ...
- 「USACO16OPEN」「LuoguP3147」262144(区间dp
P3147 [USACO16OPEN]262144 题目描述 Bessie likes downloading games to play on her cell phone, even though ...
随机推荐
- cdh 5.13 hadoop 集群IP变更详细步骤
1.因一些不可抗因素,集群IP变更. 修改CM的数据库IP地址 /etc/cloudera-scm-server/db.p... 2.修改每个主机的hosts列表 3.修改SCM数据库的hosts表中 ...
- Example of Formalising a Grammar for use with Lex & Yacc
Here is a sample of a data-file that we want to try and recognise. It is a list of students and info ...
- Sigma Function (平方数与平方数*2的约数和是奇数)
Sigma Function https://vjudge.net/contest/288520#problem/D Sigma function is an interesting function ...
- Codeforces Beta Round #44 (Div. 2)
Codeforces Beta Round #44 (Div. 2) http://codeforces.com/contest/47 A #include<bits/stdc++.h> ...
- TZOJ 1513 Farm Tour(最小费用最大流)
描述 When FJ's friends visit him on the farm, he likes to show them around. His farm comprises N (1 &l ...
- tomcat启动闪退之内存不足及显著优化
增大内存: 打开catalina.bat,@echo off回车输入 set JAVA_OPTS=-server -Xms256m -Xmx512m -XX:PermSize=128M -XX:Ma ...
- swift - 添加定时器
mport UIKit /// 控制定时器的类 class ZDTimerTool: NSObject { /// 定时器 // private var timer: Timer? /// GCD定时 ...
- [leetcode]694. Number of Distinct Islands你究竟有几个异小岛?
Given a non-empty 2D array grid of 0's and 1's, an island is a group of 1's (representing land) conn ...
- 使用PHP来简单的创建一个RPC服务
RPC全称为Remote Procedure Call,翻译过来为"远程过程调用".主要应用于不同的系统之间的远程通信和相互调用. 比如有两个系统,一个是PHP写的,一个是JAVA ...
- 解决input 有readonly属性 各个浏览器的光标兼容性问题
<input type='text' readonly unselectable='on' onfocus='this.blur()'/> 目标:input 只能读,但是在ie.火狐浏览器 ...