一道另类的区间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 ...
随机推荐
- computed
Vue.js在模板表达式中限制了,绑定表达式最多只能有一条表达式,但某些数据需要一条以上的表达式运算实现,此时就可以将此数据放在计算属性(computed)当中. Vuejs中关于computed ...
- pta7-20 畅通工程之局部最小花费问题(Kruskal算法)
题目链接:https://pintia.cn/problem-sets/15/problems/897 题意:给出n个城镇,然后给出n×(n-1)/2条边,即每两个城镇之间的边,包含起始点,终点,修建 ...
- hadoop深入简出(二)
1.上传文件 Hadoop fs -put hello.txt / 2.查看上传的文件 hadoop fs -ls / hadoop fs -text /hello.txt 两个命令都可以 3.创建文 ...
- .net 报错access to the path c:\tempimagefiles\msc_cntr_0.txt is denied
报错信息: 解决方法: 在 Web.Config 的 <System.Web> 里加 <identity impersonate="true"/> 节点即可 ...
- Unity之Application.runInBackground = true
默认是False, 设置 Application.runInBackground = true; 则 void OnApplicationPause(bool pause) 不再起作用
- @ResponseBody使用须知
-------------------siwuxie095 @ResponseBody 使用须知 使用 @ResponseBody 注解映射响应体 @ResponseBody 注解可被应用于方法上,标 ...
- Python: print stdout同行输出
项目中发现,PyCharm运行youtube_dl下载,其进度在同行显示,即替换上行输出. 稍做研究,记录下来: #coding=utf-8 from __future__ import print_ ...
- load balancer does not have available server for client: provider
Ask Question up vote6down votefavorite 4 I'm trying to use Feign client. Below is my feing client: i ...
- 将之前的Power idea公司的数据按照下图所示的格式在屏幕上显示出来。
之前的文章 示例代码如下 assume cs:codesg ;将整个data段看作是一个数组,长度一共为 ;21*4+21*4+2*21=168+42=210字节 data segment db ' ...
- 解决jenkins的内存溢出问题
在jenkins的控制台会看到如下信息: FATAL: Remote call on ime_checkcode failed java.io.IOException: Remote call on ...