当前位置:网站首页>最长上升子序列
最长上升子序列
2022-07-28 22:33:00 【Ding Jiaxiong】
题目
给定一个长度为 N 的数列,求数值严格单调递增的子序列的长度最长是多少。
输入格式
第一行包含整数 N。
第二行包含 N 个整数,表示完整序列。
输出格式
输出一个整数,表示最大长度。
数据范围
1≤N≤1000,
−109≤数列中的数≤109
输入样例:
7
3 1 2 1 8 5 6
输出样例:
4
思路分析


题解
#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++){
//空集的时候,即只有一个数
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;
}

边栏推荐
- MySQL stored procedure
- 动态规划问题(六)
- Where is sandbox's confidence in rejecting meta's acquisition of meta universe leader sand?
- [CNN] Why is the convolution kernel size of CNN usually odd
- MySQL的存储过程
- The difference between {} and ${}
- ES6 operation tutorial
- Cause analysis of 12 MySQL slow queries
- html+css+php+mysql实现注册+登录+修改密码(附完整代码)
- Develop effective Tao spell
猜你喜欢

跳表的原理

Simple use and understanding of laravel message queue

Idea connection database

Real time data warehouse: meituan's implementation of real-time data warehouse construction based on Flink

Exchange 2013 SSL certificate installation document

动态规划问题(八)

html+css+php+mysql实现注册+登录+修改密码(附完整代码)

Install MySQL using Yum for Linux

时间序列统计分析

Leetcode62. Different paths
随机推荐
Develop effective Tao spell
Real time data warehouse: meituan's implementation of real-time data warehouse construction based on Flink
Concurrency in go
DCAT in laravel_ Admin preliminary use record
mysql中exists的用法详解
Feign call fails. JSON parse error illegal character ((ctrl-char, code 31)) only regular white space (R
递归/回溯刷题(中)
vscode下链接远程服务器安装插件失败、速度慢等解决方法
动态规划问题(一)
Dynamic programming problem (3)
Dynamic programming problem (2)
Dynamic programming problem (1)
Compilation principle research study topic 2 -- recursive descent syntax analysis design principle and Implementation
How can Plato obtain premium income through elephant swap in a bear market?
Where is sandbox's confidence in rejecting meta's acquisition of meta universe leader sand?
动态规划问题(三)
Web系统常见安全漏洞介绍及解决方案-sql注入
Install mysql5.7 under Linux, super detailed complete tutorial, and cloud MySQL connection
@Transactional 注解使用详解
Alibaba Code代码索引技术实践:为Code Review提供本地IDE的阅读体验