题解 | #最大上升子序列和#
最大上升子序列和
https://www.nowcoder.com/practice/dcb97b18715141599b64dbdb8cdea3bd
#include <iostream>
using namespace std;
const int N = 1100;
int f[N];
int a[N];
int main() {
int n, ans = 0;
cin >> n;
for(int i = 1;i <= n;i++)
{
cin >> a[i];
f[i] = a[i];
for(int j = 1;j < i;j++)
{
if(a[j] < a[i])f[i] = max(f[i],f[j] + a[i]);
}
ans = max(ans,f[i]);
}
cout << ans << endl;
return 0;
}
查看6道真题和解析