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 yxj725 @ 2024-09-15 11:56:47
我服了我跟我们老师代码一模一样QWQ结果我40QWQ
by piyuhan666 @ 2024-09-15 11:57:14
不是f[n]. @yxj725
by liujinxv123 @ 2024-09-15 11:58:13
是不是该输出
by tianyun4188awa @ 2024-09-15 11:58:17
是不是要求和(新手勿喷)
by liujinxv123 @ 2024-09-15 11:58:53
不是求和,是取最大值
by tianyun4188awa @ 2024-09-15 11:59:26
@liujinxv123 学到了谢谢大佬
by liujinxv123 @ 2024-09-15 11:59:30
建议学一下线性dp(或者复习一下)
by liujinxv123 @ 2024-09-15 12:00:09
@yxj725
by piyuhan666 @ 2024-09-15 12:03:53
还要遍历求最大值
by yxj725 @ 2024-09-15 21:10:27
@piyuhan666 你有时间给我发个代码呗QWQ.我绞尽脑汁都没想出来