题意:

第一场div3, 求的是一个序列中最长连续(a,a+1,a+2...)子序列。

分析:

设一个DP[i] 表示 序列以i结尾的最长长度, 一开始都设为0。

那么如果这个数是a, 他的最长长度就是 Dp[a-1] + 1, 最后找出最大那个值就是答案, 倒回去输出序列就可以了

#include <bits/stdc++.h>
using namespace std;
const int maxN = 2e5 + ;
int a[maxN];
map<int, int> dp;
int main(){
ios::sync_with_stdio(false);
int n;
cin >> n;
int maxCnt = -, last;
for(int i = ;i <= n; i++){
int temp;
cin >> temp;
a[i] = temp;
dp[temp] = dp[temp-] + ;
if(dp[temp] > maxCnt){
maxCnt = dp[temp];
last = temp;
}
}
cout << maxCnt << "\n";
int b = last;
vector<int> ans;
for(int i = n; i >= ; i--){
if(a[i] == last){
ans.push_back(i);
last--;
}
}
reverse(ans.begin(), ans.end());
for(int i = ; i < ans.size(); i++){
cout << ans[i] << ' ';
}
}

CF 977 F. Consecutive Subsequence的更多相关文章

  1. codeforce 977 F. Consecutive Subsequence

    F. Consecutive Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input s ...

  2. Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)

    题目:https://codeforces.com/problemset/problem/977/F 题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1 思路:dp,O(n)复杂度, ...

  3. Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (DP)

    题意:给你一个长度为\(n\)的序列,求一个最长的\({x,x+1,x+2,.....,x+k-1}\)的序列,输出它的长度以及每个数在原序列的位置. 题解:因为这题有个限定条件,最长序列是公差为\( ...

  4. CF 633 F. The Chocolate Spree 树形dp

    题目链接 CF 633 F. The Chocolate Spree 题解 维护子数答案 子数直径 子数最远点 单子数最长直径 (最长的 最远点+一条链) 讨论转移 代码 #include<ve ...

  5. Codeforces 977F - Consecutive Subsequence - [map优化DP]

    题目链接:http://codeforces.com/problemset/problem/977/F 题意: 给定一个长度为 $n$ 的整数序列 $a[1 \sim n]$,要求你找到一个它最长的一 ...

  6. Consecutive Subsequence CodeForces - 977F(dp)

    Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把 ...

  7. [CF977F]Consecutive Subsequence

    题目描述 You are given an integer array of length n. You have to choose some subsequence of this array o ...

  8. Consecutive Subsequence CodeForces - 977F (map优化DP)·

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

  9. Consecutive Subsequence (DP+map)

    You are given an integer array of length nn. You have to choose some subsequence of this array of ma ...

随机推荐

  1. hdu1102 Constructing Roads 基础最小生成树

    //克鲁斯卡尔(最小生成树) #include<cstdio> #include<iostream> #include<algorithm> using names ...

  2. first-child和last-child选择器 nth-child(n)第几个元素 nth-last-child(n)倒数第几个元素

    :first-child 和  :last-child 分别表示父元素中第一个 或者  最后一个 子元素设置样式,如上图

  3. selenium自动化测试实例

    11.1使用JavaScripExecutor单击元素 被测试网页:http://www.sogou.com Java代码 public class NewTest {      WebDriver  ...

  4. 正则表达式exec方法的陷阱

    http://www.w3school.com.cn/jsref/jsref_exec_regexp.asp exec() 方法的功能非常强大,它是一个通用的方法,而且使用起来也比 test() 方法 ...

  5. 对protected修饰符的范围用代码说明(同时说明用protected修饰的属性,在继承时,一定程度上破坏了封装)

    目录结构: 本类: 本包: 子孙类: 其他包:

  6. 移动端UI自动化Appium测试——Android系统下使用uiautomator viewer查找元素

        在利用Appium做自动化测试时,最重要的一步就是获取对应的元素值,根据元素来对对象进行对应的操作,如何获得对象元素呢?Appium Server Console其实提供了一个界面对话框&qu ...

  7. AJPFX关于枚举,泛型详解

    枚举类型是JDK5.0的新特征.Sun引进了一个全新的关键字enum来定义一个枚举类.下面就是一个典型枚举类型的定义:public enum Color{RED,BLUE,BLACK,YELLOW,G ...

  8. 探究SQL添加非聚集索引,性能提高几十倍之谜

    上周,技术支持反映:客户的一个查询操作需要耗时6.1min左右,在跟进代码后,简化了数据库的查询后仍然收效甚微.后来,技术总监分析了sql后,给其中的一个表添加的一个非聚集索引(三个字段)后,同样的查 ...

  9. IOS访问webserver接口

    接口调用参数只能是字符串格式,返回格式支持3种(字符串,数组,DataSet) 需要引用第三方库,包含(DataSet,PlatServinceDataParser,WebserviceCommon, ...

  10. android studio 生成 jniLibs 目录

    现在一般的项目都会加入第三方jar包,第三方jar包我们会新建一个文件夹:libs,然后jar包都放在这个文件夹中. 但我们会发现,只是新建一个文件加之后,在AndroidStudio的左侧并不会出现 ...