当前位置:网站首页>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 
边栏推荐
- OpenCV中cv2.VideoWriter_fourcc()函数和cv2.VideoWriter()函数的结合使用
- Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
- Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
- 区间DP AcWing 282. 石子合并
- Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
- The second composition template of postgraduate entrance examination English / chart composition, English chart composition is enough
- 线性DP AcWing 902. 最短编辑距离
- Openssh remote enumeration username vulnerability (cve-2018-15473)
- AI mid stage technology research
- C#运算符
猜你喜欢

bellman-ford AcWing 853. 有边数限制的最短路
![[ybtoj advanced training guide] similar string [string] [simulation]](/img/eb/acfefc7f85018fe9365d13502e2b0a.jpg)
[ybtoj advanced training guide] similar string [string] [simulation]

AAAI 2022 | Peking University & Ali Dharma Institute: pruning and compression of pre training language model based on comparative learning

AI mid stage technology research

spfa AcWing 851. SPFA finding the shortest path

Openssh remote enumeration username vulnerability (cve-2018-15473)

深拷贝 事件总线

JS6day(DOM结点的查找、增加、删除。实例化时间,时间戳,时间戳的案例,重绘和回流)

Lekao: 22 year first-class fire engineer "technical practice" knowledge points

通过反射执行任意类的任意方法
随机推荐
This "little routine" is set on the dough cake of instant noodles. No wonder programmers are always hungry
Use MySQL events to regularly perform post seven world line tasks
IPhone 6 plus is listed in Apple's "retro products" list
Js8day (rolling event (scroll family), offset family, client family, carousel map case (to be done))
ArrayList与LinkedList效率的对比
Find the common ancestor of any two numbers in a binary tree
Typora+docsify quick start
Drools executes string rules or executes a rule file
堆 AcWing 838. 堆排序
包管理工具
百款拿来就能用的网页特效,不来看看吗?
传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
区间DP AcWing 282. 石子合并
High performance erasure code coding
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Drools executes the specified rule
JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
JDBC prevent SQL injection problems and solutions [preparedstatement]
哈希表 AcWing 841. 字符串哈希
Redis transaction mechanism implementation process and principle, and use transaction mechanism to prevent inventory oversold