题目:https://codeforces.com/problemset/problem/977/F

题意:一个序列,求最长单调递增子序列,但是有一个要求是中间差值都是1

思路:dp,O(n)复杂度,我们想一下O(n^2)时的最长递增子序列,我们第二个循环要遍历前面所有的如果大于长度就加1,代表以这个数结尾的最长长度是多少,

因为中间差值不定,所以我们遍历整个循环,这个题设置中间差值只能是1,所以我们递推式就可以是   dp[i]=max(dp[i],dp[i-1]+1),用map来映射值即可

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<map>
#include<string>
#include<cstring>
#include<iostream>
#include<vector>
#define mod 1000000007
#define maxn 200005
using namespace std;
typedef long long ll;
map<ll,ll> mp;
ll n,a[maxn];
int main()
{cin>>n;for(int i=1;i<=n;i++){cin>>a[i];}for(int i=1;i<=n;i++){mp[a[i]]=max(mp[a[i]],mp[a[i]-1]+1);} ll mx=mp[a[1]];ll dex=1;for(int i=2;i<=n;i++){dex=mx>mp[a[i]]?dex:i;mx=max(mx,mp[a[i]]);}ll c=a[dex]-mx+1;cout<<mx<<endl;for(int i=1;i<=n;i++){if(a[i]==c){printf("%d ",i);c++; }    }
}

转载于:https://www.cnblogs.com/Lis-/p/10752016.html

Codeforces Round #479 (Div. 3) F. Consecutive Subsequence (简单dp)相关推荐

  1. Codeforces Round #630 (Div. 2) F. Independent Set 树形dp

    传送门 文章目录 题意: 思路: 题意: 给你一棵树,求这棵树的边导出子图中独立集的数量和,独立集大小可以为000. 思路: 先考虑普通的独立集数量怎么求,无非就是分情况讨论一下选根还是不选根,而这个 ...

  2. Codeforces Round #699 (Div. 2) F - AB Tree(贪心、树上DP)超级清晰,良心题解,看不懂来打我 ~

    整理的算法模板合集: ACM模板 点我看算法全家桶系列!!! 实际上是一个全新的精炼模板整合计划 Codeforces Round #699 (Div. 2) F - AB Tree Problem ...

  3. Codeforces Round #479 (Div. 3)【完结】

    2022.2.28 开始复盘div3 题目链接:https://codeforces.com/contest/977 目录 A. Wrong Subtraction[签到模拟题] B. Two-gra ...

  4. Codeforces Round #644 (Div. 3) F.Spy-string

    Codeforces Round #644 (Div. 3) F.Spy-string 题目链接 You are given n strings a1,a2,-,an: all of them hav ...

  5. Codeforces Round #849 (Div. 4) F. Range Update Point Query

    Codeforces Round #849 (Div. 4) F. Range Update Point Query 题目大意: 给一串数字,有两个操作: 操作1:将 l − r l-r l−r 的数 ...

  6. Codeforces Round #636 (Div. 3) C.Alternating Subsequence

    Codeforces Round #636 (Div. 3) C.Alternating Subsequence 题目链接 Recall that the sequence b is a a subs ...

  7. Codeforces Round #538 (Div. 2) F. Please, another Queries on Array? 线段树 + 欧拉函数

    传送门 文章目录 题意: 思路: 题意: 给你一个序列aaa,你需要实现两种操作: (1)(1)(1) 将[l,r][l,r][l,r]的aia_iai​都乘rrr. (2)(2)(2) 求ϕ(∏i= ...

  8. Codeforces Round #742 (Div. 2) F. One-Four Overload 构造 + 二分图染色

    传送门 文章目录 题意: 思路: 题意: 给你一个n∗mn*mn∗m的矩形,包含...和XXX,你有两种颜色,你需要给...染色使得每个XXX上下左右相邻的...其两种颜色个数相同,输出一种合法方案. ...

  9. Codeforces Round #740 (Div. 2) F. Top-Notch Insertions 线段树 / 平衡树 + 组合数学

    传送门 文章目录 题意: 思路: 题意: 思路: 考虑最终的序列是什么鸭子的,首先序列肯定单调不降,也就是a1≤a2≤a3≤...≤ana_1\le a_2\le a_3\le ...\le a_na ...

  10. Codeforces Round #585 (Div. 2) F. Radio Stations 2-sat + 神仙建模

    传送门 文章目录 题意: 思路: 题意: 你现在有ppp种电台,有nnn对关系(x,y)(x,y)(x,y)代表xxx电台或yyy电台中至少有一个,mmm对关系(x,y)(x,y)(x,y)代表xxx ...

最新文章

  1. [转] Java多线程发展简史
  2. Windows按名称排序问题
  3. tanh python_带有Python示例的math.tanh()方法
  4. Java 项目开发及管理常用工具收集
  5. Linear Color Space 渲染时几点注意
  6. Unity3D之UGUI基础9:ScrollRect卷动区域
  7. 精灵骑士二觉_守护者二觉转职分析 精灵骑士二觉能有多强
  8. android horizontalscrollview属性,Android 实例讲解HorizontalScrollView实现左右滑动
  9. 使用Chrome开发者工具精确定位网页元素位置
  10. artdialog ajax新增,artDialog 对话框组件使用简介
  11. 重新连接 到 时出错 Microsoft Windows Network:本地设备名已在使用中
  12. TCP/IP协议知多少
  13. c语言多线程编程随机数,在c 中使用线程安全的随机数,多线程_c_开发99编程知识库...
  14. 运维工程师的工作内容有哪些?能详细列举一下吗?
  15. Untiy添加水印并保存(包含文字转图片并打水印)
  16. java timer schedule_Java Timer的使用,timer.schedule定时执行
  17. CMake问题:The CXX compiler identification is unknown
  18. c# UTC时间和本地时间转换(北京时间)
  19. java 1.13 快照下载_Minecraft Java快照版18w15a下载
  20. PDF格式分析(五十九) Color Spaces 颜色空间

热门文章

  1. Module build failed (from ./node_modules/postcss-loader/src/index.js):
  2. Security+ 学习笔记51 风险分析
  3. 加权二叉树的实现与单元测试(python)
  4. Thread 类的属性和方法
  5. cluster(3)
  6. 子慕谈设计模式系列(一)
  7. linux下的raid及mdadm的命令详解
  8. direct3d Colorkey 应用.
  9. IIS 如何用同一IP解析不同域名到同一服务器
  10. 6.4 First Missing Positive --- 图解