当前位置:网站首页>最长上升子序列
最长上升子序列
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;
}
边栏推荐
- SQL implementation merges multiple rows of records into one row
- html+css+php+mysql实现注册+登录+修改密码(附完整代码)
- Laptop external display
- Concurrency in go
- Real time data warehouse: meituan reviews Flink's real-time data warehouse application sharing
- Advanced area of attack and defense world web masters unserialize3
- NPM replace the latest Taobao image
- Detailed explanation of the usage of exists in MySQL
- Dynamic programming problem (6)
- Application of Devops in Internet of things solutions
猜你喜欢
Real time data warehouse: Netease strictly selects the practice of real-time data warehouse based on Flink
[micro services ~nacos] Nacos service providers and service consumers
IDEA 连接 数据库
动态规划问题(五)
Web系统常见安全漏洞介绍及解决方案-CSRF攻击
How can Plato obtain premium income through elephant swap in a bear market?
MySQL transaction (this is enough...)
DCAT in laravel_ Admin preliminary use record
Laravel8 middleware realizes simple permission control
Develop effective Tao spell
随机推荐
熊市下PLATO如何通过Elephant Swap,获得溢价收益?
#{}和${}的区别
Have passed hcip and joined the company of your choice, and share the learning experience and experience of Huawei certification
CV target detection model sketch (2)
Use hutool tool class to operate excel with more empty Sheet1
CV semantic segmentation model sketch (2)
Detailed explanation of the usage of exists in MySQL
Dynamic programming problem (4)
Okaleido ecological core equity Oka, all in fusion mining mode
SQL implementation merges multiple rows of records into one row
Oracle超全SQL,细节狂魔
Cmake basic learning
[CNN] Why is the convolution kernel size of CNN usually odd
还在写大量 if 来判断?一个规则执行器干掉项目中所有的 if 判断...
@Detailed explanation of the use of transactional annotation
Applet verification code login
Introduction and solution of common security vulnerabilities in web system CSRF attack
Why is it so difficult for the SEC to refuse the application for transferring gray-scale GBTC to spot ETF? What is the attraction of ETF transfer?
R语言怎么学
IDEA2021.2安装与配置(持续更新)