当前位置:网站首页>Longest ascending subsequence
Longest ascending subsequence
2022-07-29 00:28:00 【Ding Jiaxiong】
subject
Given a length of N Sequence of numbers , Find the longest length of a strictly monotonically increasing subsequence .
Input format
The first line contains integers N.
The second line contains N It's an integer , Represents a complete sequence .
Output format
Output an integer , Represents the maximum length .
Data range
1≤N≤1000,
−109≤ The number in a sequence ≤109
sample input :
7
3 1 2 1 8 5 6
sample output :
4
Thought analysis


Answer key
#include<iostream>
using namespace std;
const int N = 1010;
int n;
int a[N] , f[N];
int main(){
scanf("%d",&n);
for(int i = 1; i <= n; i ++){
scanf("%d",&a[i]);
}
for(int i = 1; i <= n ; i++){
// When empty set , That is, there is only one number
f[i] = 1;
for(int j = 1;j <= i; j++){
if(a[j] < a[i]){
f[i] = max(f[i] , f[j] + 1);
}
}
}
int res = 0;
for(int i = 1; i <= n; i++){
res = max(res , f[i]);
}
printf("%d\n",res);
return 0;
}

边栏推荐
- R语言怎么学
- What does WGet mean
- Idea connection database
- Using recursion and chain header interpolation to realize the group turnover of linked lists -- leetcode25 K group turnover linked lists
- PTA (daily question) 7-71 character trapezoid
- ES6 operation tutorial
- [applet project development -- JD mall] uni app commodity classification page (first)
- "Method not allowed", 405 problem analysis and solution
- Field injection is not recommended solution
- The difference between {} and ${}
猜你喜欢

Do like and in indexes in MySQL go

CV target detection model sketch (2)

Idea connection database

PTA (daily question) 7-73 turning triangle

Idea2021.2 installation and configuration (continuous update)

Advanced area of attack and defense world web masters unserialize3

Advanced area of attack and defense world web masters warmup

PHP语言基础知识(超详细)

Attack and defense world web master advanced area php2

17.机器学习系统的设计
随机推荐
ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
Newscenter, advanced area of attack and defense world web masters
Software designer - intermediate, exam summary
@Transactional 注解使用详解
Idea2021.2 installation and configuration (continuous update)
110 MySQL interview questions and answers (continuously updated)
动态规划问题(八)
Intelligent trash can (VII) -- Introduction and use of sg90 steering gear (Pico implementation of raspberry pie)
动态规划问题(三)
Detailed explanation of the usage of exists in MySQL
Erc20 Standard Code
Sword finger offer 55 - I. depth of binary tree
Network traffic monitoring tool iftop
Feign call fails. JSON parse error illegal character ((ctrl-char, code 31)) only regular white space (R
Advanced area of attack and defense world web masters training www robots
Basic knowledge of PHP language (super detailed)
vulnhub:BTRSys2
Recursion / backtracking (Part 2)
Introduction and solution of common security vulnerabilities in web system CSRF attack
@PostConstruct注解详解