yxj725 @ 2024-09-15 11:54:40
#include<bits/stdc++.h>
using namespace std;
int n,a[5010],f[5010];
int main (){
cin>>n;
for (int i=1;i<=n;i++) {
cin>>a[i];
f[i]=1;
}
for (int i=2;i<=n;i++) {
for (int j=1;j<i;j++) {
if (a[j]<a[i]) {
f[i]=max(f[i],f[j]+1);
}
}
}
cout<<f[n];
return 0;
}
by Moco_jof @ 2024-09-16 12:22:41
#include <iostream>
#include <algorithm>
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;
}
by Moco_jof @ 2024-09-16 12:24:18
@yxj725
by yxj725 @ 2024-09-17 16:56:08
@Moco_jof 谢谢已关
by Ryan2024hcy @ 2024-09-22 15:45:05
#include<bits/stdc++.h>
using namespace std;
int a[30000],b[30000],s[30000],maxn=-1;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
s[i]=1;
b[i]=a[i];
}
for(int i=1;i<=n;i++){
for(int j=1;j<=i;j++){
if(b[j]<a[i]){
s[i]=max(s[j]+1,s[i]);
}
maxn=max(maxn,s[i]);
}
}
cout<<maxn;
}
by wangmingrui123456 @ 2024-10-10 20:17:22
每一个位置都可以作为一个新的最长上升子序列的第一项
by wangmingrui123456 @ 2024-10-10 20:18:00
当我没说