一道另类的区间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 ...
随机推荐
- 188. Best Time to Buy and Sell Stock IV (Array; DP)
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- http://www.bugku.com:Bugku——备份是个好习惯(http://120.24.86.145:8002/web16/)
看了bugku的这道题,陌生又熟悉. 题目首先说[备份是个好习惯],访问网站只有一串字符,,,,,emmmmm,这句话表明人家经常做备份,所以咯,肯定在网站哪里备份有网页信息.嘻嘻 1 ...
- Ionic3错误: StaticInjectorError[HttpModule]: NullInjectorError: No provider for HttpModule!
先在app.module.ts中导入HttpModule,才能在构造函数中注入Http. Ionic自动构建项目时,并没有导入HttpModule. 解决方案:打开app.module.ts,加入导入 ...
- echarts中国地图坐标弹框
echarts链接:http://gallery.echartsjs.com/editor.html?c=xHkdOlpwWz 代码: var geoCoordMap = { '上海': [121.4 ...
- swift - 加速器/摇一摇功能
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- 纯css实现div中未知尺寸图片的垂直居中
1.淘宝的方法 在曾经的"淘宝UED招聘"中有这样一道题目: “使用纯CSS实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中.” 当然出题并不是 ...
- c语言使用指针对int数组的求和
#include <stdio.h> int sump(int *, int *); int main(void) { , , , , }; printf()); ; } int sump ...
- vue2.0细节剖析
1.样式切换 单个切换样式 /*html部分*/ <div class="bg" v-bind:class="{active:isActive}"> ...
- Fiddler抓包使用教程-安装配置
转载请标明出处:http://blog.csdn.net/zhaoyanjun6/article/details/72876628 本文出自[赵彦军的博客] Fiddler是什么? Fiddler是一 ...
- js的回调函数详解
本文主要介绍了个人对于javascript中回调函数的理解和使用方法及示例,需要的朋友可以参考下 现在做native App 和Web App是主流,也就是说现在各种基于浏览器的web app框 ...