jyxnb @ 2023-10-17 20:40:34
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <cctype>
#include <queue>
#include <deque>
#include <ctime>
#include <cstring>
#include <string>
#define _e putchar (' ')
#define _v putchar ('\n')
#define ll long long
#define INF 999999999999999999ll
#define INE -999999999999999999ll
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;
inline int lowbit (int x) {
return x&(-x);
}
inline int mx(int x,int y) {
return x>y?x:y;
}
inline int mn(int x,int y) {
return x<y?x:y;
}
inline void rd(int &x) {
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<<1)+(s<<3)+(ch^48); ch=getchar ();}
x=s*w;
}
inline void wr(int x) {
if(x<0) x=-x,putchar (45);
if(x<10) {
putchar (x+48);
return ;
}
wr(x/10);
putchar (x%10+48);
}
inline int ab (int x) {
if(x<0) return -x;
return x;
}
inline void swap (int &x,int &y) {
x^=y^=x^=y;
}
const int N=100005;
int n,a[N],mem[N];
inline int dfs (int num) {
if (mem[num]) return mem[num];
if (num==n+1) return mem[num]=0;
int maxn=-1e9;
for (int i=1;i<num;i++) {
if (a[num]>a[i]) {
maxn=mx(maxn,dfs (i)+1);
}
}
return mem[num]=maxn;
}
int main () {
rd(n);
mem[1]=1;
for (int i=1;i<=n;i++) rd(a[i]);
int maxx=-(1e9);
for (int i=1;i<=n;i++) maxx=mx(maxx,dfs(i));
wr(maxx),_v;
return 0;
}
by jinyouchen1111111 @ 2024-08-08 09:48:30
@jyxnb
#include<iostream>
using namespace std;
int main(){
int l,k;
int a[5005][5005];
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[1][i];
a[2][i]=1;a[3][i]=0;
}
for(int i=n-1;i>=1;i--){
l=0;k=0;
for(int j=i+1;j<=n;j++){
if(a[1][j]>a[1][i]&&a[2][j]>l){
l=a[2][j];
k=j;
}
if(l>0){
a[2][i]=l+1;
a[3][i]=k;
}
}
}
k=1;
for(int j=1;j<=n;j++){
if(a[2][j]>a[2][k]){
k=j;
}
}
cout<<a[2][k]<<endl;
return 0;
}
求关