首页 > 其他分享 >674.longest-continuous-increasing-subsequence 最长连续递增序列

674.longest-continuous-increasing-subsequence 最长连续递增序列

时间:2022-10-30 17:11:08浏览次数:83  
标签:nums 674 递增 continuous int subsequence 序列 dp

问题描述

674.最长连续递增序列

解题思路

dp[i]表示以nums[i - 1]结尾的最长连续递增子序列长度;

递推关系为:

if (nums[i - 1] > nums[i - 2])
    dp[i] = dp[i - 1] + 1;

代码

class Solution {
  public:
    int findLengthOfLCIS(vector<int> &nums) {
        vector<int> dp(nums.size() + 1, 1);
        int m = 1;
        for (int i = 2; i <= nums.size(); i++) {
            if (nums[i - 1] > nums[i - 2])
                dp[i] = dp[i - 1] + 1;
            if (dp[i] > m)
                m = dp[i];
        }
        return m;
    }
};

标签:nums,674,递增,continuous,int,subsequence,序列,dp
From: https://www.cnblogs.com/zwyyy456/p/16841679.html

相关文章

  • 可观测可回溯 | Continuous Profiling 实践解析
    作者:虚镜概述ContinuousProfiling在软件开发生命周期的位置CI/CD的概念非本文重点,不解释了。从上图可以看出。ContinuousProfiling(持续性能分析,下文简称为CP)是生产向开......
  • 可观测可回溯 | Continuous Profiling 实践解析
    作者:虚镜概述ContinuousProfiling在软件开发生命周期的位置CI/CD的概念非本文重点,不解释了。从上图可以看出。ContinuousProfiling(持续性能分析,下文简称为CP)是生产向开......
  • Codeforces 1674 E. Breaking the Wall
    题意给n个数的数列a[n],可以进行任意次操作,每次选取一个位置i,a[i]-=2,a[i-1]-=1,a[i+1]-=1,问最少几次操作可以让任意两个值<=0提示需要进行分类讨论,分成三种情况讨论1.......
  • csu 1551: Longest Increasing Subsequence Again BIT + 思维
    预处理last[i]表示以第i个开始,的合法后缀。pre[i]表示以第i个结尾,的合法前缀。那么每一个数a[i],肯定是一个合法后缀last[i]+一个合法前缀,那么合法前缀的数字要小于a[i],并......
  • [Oracle] LeetCode 300 Longest Increasing Subsequence
    Givenanintegerarraynums,returnthelengthofthelongeststrictlyincreasingsubsequence.Asubsequenceisasequencethatcanbederivedfromanarrayby......
  • ARC150F Constant Sum Subsequence 解题记录
    题意:给定长度为\(n\)的序列\(A\),保证对每个\(i\in[1,S]\),\(i\)都在\(A\)中出现了至少一次。令\(X\)表示\(A\)重复\(S\)次组成的序列。求最小的\(L\),满足:......
  • Codeforces Round #825 (Div. 2)D. Equal Binary Subsequences
    CodeforcesRound#825(Div.2)D.EqualBinarySubsequences题意:给定一个长度为2n的01字符串s。你可以对其中一个子序列进行向右旋转一个位置。问能否将字符串分割成......
  • Subsequence Path(图论,DP)
    题意给定\(N\)个点,\(M\)条边的无向图,边权为\(C_i\)。给定一个序列\(E=(E_1,E_2,\dots,E_K)\),其中\(E_i\)表示边的编号。路径是“好路径”当且仅当边的编号按照经过......
  • D1. Xor-Subsequence (easy version)
    D1.Xor-Subsequence(easyversion)https://codeforces.ml/problemset/problem/1720/D1题意给你长度为n的数组a让你找出a最长的子序列满足\(a_b_p*b_p+1<a_b_p+1......
  • LeetCode 792. Number of Matching Subsequences
    原题链接在这里:https://leetcode.com/problems/number-of-matching-subsequences/题目:Givenastring s andanarrayofstrings words,return thenumberof wor......