当前位置:网站首页>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 
边栏推荐
- Some sudden program ideas (modular processing)
- . Net wechat message template push
- 高性能纠删码编码
- JDBC prevent SQL injection problems and solutions [preparedstatement]
- JS8day(滚动事件(scroll家族),offset家族,client家族,轮播图案例(待做))
- LTC3307AHV 符合EMI标准,降压转换器 QCA7005-AL33 PHY
- 怎样写一篇赏心悦目的英文数学论文
- Anxiety of a 211 programmer: working for 3 years with a monthly salary of less than 30000, worried about being replaced by fresh students
- Redis sentinel mechanism and configuration
- Oracle从入门到精通(第4版)
猜你喜欢

Redis bloom filter

线性DP AcWing 897. 最长公共子序列

Efficiency comparison between ArrayList and LinkedList

Lekao.com: experience sharing of junior economists and previous candidates in customs clearance

Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution

Redis sentinel mechanism and configuration

C#运算符

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

There is a hidden danger in CDH: the exchange memory used by the process of this role is XX megabytes. Warning threshold: 200 bytes

Openssh remote enumeration username vulnerability (cve-2018-15473)
随机推荐
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
哈希表 AcWing 841. 字符串哈希
Input box assembly of the shutter package
Heap acwing 838 Heap sort
AI mid stage technology research
Drools terminates the execution of other rules after executing one rule
Distributed machine learning framework and high-dimensional real-time recommendation system
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
spfa AcWing 851. SPFA finding the shortest path
Window10 upgrade encountered a big hole error code: 0xc000000e perfect solution
Bom Dom
3 A VTT端接 稳压器 NCP51200MNTXG资料
传感器 ADXL335BCPZ-RL7 3轴 加速度计 符合 RoHS/WEEE
Adding database driver to sqoop of cdh6
. Net wechat message template push
js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
MySQL and PostgreSQL methods to grab slow SQL
Mongodb redis differences
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
Lekao.com: experience sharing of junior economists and previous candidates in customs clearance