当前位置:网站首页>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;
}

边栏推荐
- vulnhub:SolidState
- Detailed explanation of the usage of exists in MySQL
- Dynamic programming problem (VII)
- Advanced area of attack and defense world web masters unserialize3
- Sword finger offer 55 - I. depth of binary tree
- Multimodal model sketch (1)
- Summary: the difference between pod and container
- CV instance segmentation model sketch (1)
- Dynamic programming problem (VIII)
- MySQL事务(transaction) (有这篇就足够了..)
猜你喜欢

AutoCAD -- import excel tables into CAD and merge CAD

17.机器学习系统的设计

Idea error running 'application' command line is too long solution

Alibaba code index technology practice: provide reading experience of local IDE for code review

I don't know how lucky the boy who randomly typed the log is. There must be a lot of overtime!

“吃货联盟定餐系统”

Web系统常见安全漏洞介绍及解决方案-sql注入

DCAT in laravel_ Admin preliminary use record

Oracle实例无法启动的问题如何解决

How to solve the problems of MQ message loss, duplication and backlog?
随机推荐
@PostConstruct注解详解
MySQL 分库分表及其平滑扩容方案
Recursion / backtracking (Part 2)
Laravel permission control
What does WGet mean
CV instance segmentation model sketch (1)
MySQL事务(transaction) (有这篇就足够了..)
Using recursion and chain header interpolation to realize the group turnover of linked lists -- leetcode25 K group turnover linked lists
What does the expression > > 0 in JS mean
PTA (daily question) 7-77 encryption
Erc20 Standard Code
vscode下链接远程服务器安装插件失败、速度慢等解决方法
Simple use and understanding of laravel message queue
ACM SIGIR 2022 | interpretation of selected papers of meituan technical team
动态规划问题(八)
聊聊异步编程的 7 种实现方式
Linux下安装Mysql5.7,超详细完整教程,以及云mysql连接
面试被问到了String相关的几道题,你能答上来吗?
Router view cannot be rendered (a very low-level error)
递归/回溯刷题(中)