jijijibeibeibei @ 2023-10-15 17:08:31
#include<iostream>
using namespace std;
int a[5005],n,num[1000],b=1;
void f(int zhi,int n){
if(n<1)return ;
if(a[n]>a[n-1]){
num[zhi]++;f(zhi,n-1);
}
}else{
b++;
f(zhi++,n-num[zhi]);
}
}
int main(){
cin>>n;
//fre[pen("文件名+后缀“,”r或w“,stdin/stdout
for(int i=1;i<=n;i++)cin>>a[i];
f(1,n);
int max1=0;
for(int i=1;i<=b;i++){
if(num[i]>max1)max1=num[i];
}
cout<<max1;
return 0;
}
好像哪里不对劲(苦笑)
by CCA_zhujunwei @ 2023-12-10 15:16:48
#include<iostream>
using namespace std;
int a[5010], dp[5010], n, maxi;
int main(){
cin>>n;
for(int i = 1;i <= n;i++){
cin>>a[i];
dp[i] = 1;
}
for(int i = 2;i <= n;i++){
for(int j = 1;j < i;j++){
if(a[i] > a[j]){
dp[i] = max(dp[i], dp[j] + 1);
}
}
maxi = max(maxi, dp[i]);
}
cout<<maxi;
return 0;
}
by CCA_zhujunwei @ 2023-12-10 15:17:56
这个我用dp做的