fengzijia @ 2024-08-31 15:33:50
#include<bits/stdc++.h>
using namespace std;
int a[5010],s[5010];
int main(){
int n,sum=1,su=0,z=0,sum1=0;
cin>>n;
for(int i=1;i<=n;i++){
cin>>s[i];
}
for(int i=1;i<=n;i++){
a[i]=s[i];
for(int j=i+1;j<=n;j++){
if(s[j]>a[sum]){
z=s[j];
for(int o=j;o<=n;o++){
if(s[o]<=z&&s[o]>a[sum]){
sum1=o;
z=s[o];
}
}
j=sum1;
sum++;
a[sum]=s[j];
}
}
su=max(su,sum);
sum=1;
}
for(int i=1;i<=n;i++){
a[i]=s[i];
for(int j=i+1;j<=n;j++){
if(s[j]>a[sum]){
sum++;
a[sum]=s[j];
}
}
su=max(su,sum);
sum=1;
}
cout<<su;
return 0;
}
by Yxy7952 @ 2024-08-31 15:40:20
@fengzijia
说真的,建议用dp做,因为这是dp模板题
by fengzijia @ 2024-08-31 15:52:48
@yixingyou 没学过怎么办
by Yxy7952 @ 2024-08-31 15:54:29
@fengzijia
对不起,我也没办法,但是这是入门dp,可以看一下TJ,看能不能看懂
by molakeser @ 2024-09-16 12:26:51
#include <bits/stdc++.h>
using namespace std;
int a[5005],b[5005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin>>n;
int maxn=0;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=1;
}
for(int i=2;i<=n;i++){
for(int j=1;j<i;j++){
if (a[j]<a[i]) {
b[i]=max(b[i],b[j]+1);
}
}
}
for(int i=1;i<=n;i++){
maxn=max(maxn,b[i]);
}
cout<<maxn;
return 0;
}
@Moco_jof @ fengzijia