You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
|
|
// 最大上升子序列和
|
|
|
|
|
int n;
|
|
|
|
|
const int N = 100010;
|
|
|
|
|
int a[N];
|
|
|
|
|
int f[N];//以第i个元素结尾的最大子序列和
|
|
|
|
|
int res;
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
cin >> n;
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i];
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
|
f[i] = a[i]; // 最大上升子序列(个数)这里是1,此处是a[i]
|
|
|
|
|
for (int j = 1; j < i; j++)
|
|
|
|
|
// 最大上升子序列(个数)这里是加1,此处是+a[i]
|
|
|
|
|
if (a[i] > a[j]) f[i] = max(f[i], f[j] + a[i]);
|
|
|
|
|
res = max(res, f[i]);
|
|
|
|
|
}
|
|
|
|
|
printf("%d ", res);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|