当前位置:网站首页>Linear DP acwing 895 Longest ascending subsequence
Linear DP acwing 895 Longest ascending subsequence
2022-07-02 12:43:00 【T_ Y_ F666】
linear DP AcWing 895. Longest ascending subsequence
Original link
AcWing 895. Longest ascending subsequence
Algorithm tags
Dynamic programming linear DP Longest ascending subsequence
Ideas
Time complexity is represented by States * State calculation
State means One dimensional array N
State calculation Enumerate one-dimensional arrays N
Time complexity O ( N 2 ) O(N^2) O(N2)
Code
#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){
// initialization f[i] Only a[i] In itself The length is 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;
}
Originality is not easy.
Reprint please indicate the source
If it helps you Don't forget to praise and support
边栏推荐
- Simple understanding of ThreadLocal
- 线性DP AcWing 898. 数字三角形
- Leetcode - Sword finger offer 59 - I, 59 - II
- Writing method of then part in drools
- [FFH] little bear driver calling process (take calling LED light driver as an example)
- 一些突然迸发出的程序思想(模块化处理)
- async/await 异步函数
- Intel internal instructions - AVX and avx2 learning notes
- Do you know all the interface test interview questions?
- Floyd AcWing 854. Floyd求最短路
猜你喜欢
VLAN experiment
计数类DP AcWing 900. 整数划分
Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold
[FFH] little bear driver calling process (take calling LED light driver as an example)
[ybtoj advanced training guide] similar string [string] [simulation]
spfa AcWing 852. spfa判断负环
模数转换器(ADC) ADE7913ARIZ 专为三相电能计量应用而设计
Hash table acwing 841 String hash
上手报告|今天聊聊腾讯目前在用的微服务架构
Adding database driver to sqoop of cdh6
随机推荐
正确遍历EntryList方法
LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Mui WebView down refresh pull-up load implementation
Deep Copy Event bus
通过反射执行任意类的任意方法
深拷貝 事件總線
线性DP AcWing 896. 最长上升子序列 II
Lekao: 22 year first-class fire engineer "technical practice" knowledge points
Openssh remote enumeration username vulnerability (cve-2018-15473)
8 examples of using date commands
接口测试面试题目,你都会了吗?
Some sudden program ideas (modular processing)
Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
哈希表 AcWing 841. 字符串哈希
基于STM32的OLED 屏幕驱动
Rust search server, rust quick service finding tutorial
线性DP AcWing 899. 编辑距离
Sse/avx instruction set and API of SIMD
Anti shake throttle