当前位置:网站首页>线性DP AcWing 895. 最长上升子序列
线性DP AcWing 895. 最长上升子序列
2022-07-02 09:43:00 【T_Y_F666】
线性DP AcWing 895. 最长上升子序列
原题链接
算法标签
动态规划 线性DP 最长上升子序列
思路
时间复杂度为状态表示*状态计算
状态表示 一维数组N
状态计算 枚举一维数组N
时间复杂度 O ( N 2 ) O(N^2) O(N2)
代码
#include<bits/stdc++.h>
#define int long long
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>b;--i)
using namespace std;
const int N = 1005, INF = 0x3f3f3f3f;
int a[N], f[N];
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n=read();
rep(i, 1, n+1){
a[i]=read();
}
rep(i, 1, n+1){
// 初始化f[i]只有a[i]本身 长度为1
f[i]=1;
rep(j, 1, i){
if(a[j]<a[i]){
f[i]=max(f[j]+1, f[i]);
}
}
}
int ans=0;
rep(i, 1, n+1){
ans=max(ans, f[i]);
}
printf("%lld", ans);
return 0;
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Differences between nodes and sharding in ES cluster
- 使用Sqoop把ADS层数据导出到MySQL
- 单指令多数据SIMD的SSE/AVX指令集和API
- Enhance network security of kubernetes with cilium
- Tas (file d'attente prioritaire)
- mysql数据库基础
- Simple use of drools decision table
- Performance tuning project case
- CDA数据分析——Excel数据处理的常见知识点归纳
- Brush questions --- binary tree --2
猜你喜欢
2.6 using recursion and stack - [tower of Hanoi problem]
Less than three months after the programmer was hired, the boss wanted to launch the app within one month. If he was dissatisfied, he was dismissed immediately
甜心教主:王心凌
Deep Copy Event bus
ThreadLocal的简单理解
Programmers can't find jobs after the age of 35? After reading this article, you may be able to find the answer
BOM DOM
BOM DOM
Discrimination of the interval of dichotomy question brushing record (Luogu question sheet)
The programmer and the female nurse went on a blind date and spent 360. He packed leftovers and was stunned when he received wechat at night
随机推荐
mysql数据库基础
CDA数据分析——AARRR增长模型的介绍、使用
Drools terminates the execution of other rules after executing one rule
Go learning notes - go based interprocess communication
深拷贝 事件总线
2.6 using recursion and stack - [tower of Hanoi problem]
FBX import under ue4/ue5 runtime
drools执行指定的规则
Introduction to CPU instruction set
Find the factorial of a positive integer within 16, that is, the class of n (0= < n < =16). Enter 1111 to exit.
Sweetheart leader: Wang Xinling
The blink code based on Arduino and esp8266 runs successfully (including error analysis)
刷题---二叉树--2
IPhone 6 plus is listed in Apple's "retro products" list
Intel 内部指令 --- AVX和AVX2学习笔记
Performance tuning project case
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
高性能纠删码编码
Drools dynamically add, modify, and delete rules
堆(优先级队列)