Consecutive Subsequence CodeForces - 977F 题目大意:输出一序列中的最大的连续数列的长度和与其对应的下标(连续是指 7 8 9这样的数列) 解题思路: 状态:把dp[i]定义为数列末尾为 i 的最大连续数列的长度值 状态转移方程:dp[i] = dp[i-1] + 1 再由最大连续数列最后一个值从后往前倒推出前面的所有值,到不是连续时停止 代码: #include<bits/stdc++.h> using namespace std; + ; int d…
You are given an integer array of length nn. You have to choose some subsequence of this array of maximum length such that this subsequence forms a increasing sequence of consecutive integers. In other words the required sequence should be equal to […
题目链接:http://codeforces.com/problemset/problem/977/F 题意: 给定一个长度为 $n$ 的整数序列 $a[1 \sim n]$,要求你找到一个它最长的一个子序列,该子序列满足单调连续递增. 子序列可以不连续,单调连续递增即例如 $[4,5,6,7]$ 或者 $[6,7,8,9,10]$ 这样的. 题解: $f[i]$ 表示以 $a[i]$ 为结尾的最长连续递增子序列,那么要转移就需要找到 $[1,i-1]$ 这个区间内,某个满足 $a[j] = a…
题目: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来映射值即可…
大意: 给定字符串, 每次询问区间[l,r]有子序列2017, 无子序列2016所需要删除的最小字符数 转移用矩阵优化一下, 要注意$(\mathbb{Z},min,+)$的幺元主对角线全0, 其余全无穷, 零元为全无穷 #include <iostream> #include <algorithm> #include <cstdio> #include <math.h> #include <set> #include <map> #…
D - Yet Another Problem On a Subsequence CodeForces - 1000D The sequence of integers a1,a2,-,aka1,a2,-,ak is called a good array if a1=k−1a1=k−1 and a1>0a1>0. For example, the sequences [3,−1,44,0],[1,−99][3,−1,44,0],[1,−99] are good arrays, and the…
F. Consecutive Subsequence time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given an integer array of length nn. You have to choose some subsequence of this array of maximum length…
题意:给你一个长度为\(n\)的序列,求一个最长的\({x,x+1,x+2,.....,x+k-1}\)的序列,输出它的长度以及每个数在原序列的位置. 题解:因为这题有个限定条件,最长序列是公差为\(1\)的单增序列,所以其实非常简单. ​ 我们用\(map\)来记录每个元素最后出现的位置,\(dp\)表示当前位置的最长序列,\(last\)表示\(x-1\)的位置. ​ \(dp\)状态有两种更新方式: 1.如果上个元素\((x-1)\)存在,则\(dp[i]=dp[x-1]+1\). ​ 2…
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 设f[i]表示i作为序列的最后一个数字,最长的连续序列的长度. 用f[i]和f[i-1]+1来转移即可 [代码] import java.io.*; import java.util.*; public class Main { static InputReader in; static PrintWriter out; public static void main(String[] args) throws IOException{…
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解了, 用线段树维护dp的值, 然后区间合并求答案. 每个节点保存dp[ i ][ j ]表示, 把当前管理的区间删到 s{2017}中的 s[ i + 1 ] - s[ j - 1 ],最少删几个, 然后合并的时候5 ^ 3合并. #include<bits/stdc++.h> #define L…