https://cn.vjudge.net/contest/310994#problem/E
这个dp就很经典了。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5, mod = 1e9 + 7;
int a[maxn], dp[maxn];//dp[i]表示以i结尾的最大值
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
int n;
while (cin >> n){
if (n == 0) break;
int ans = 0;
for (int i = 0; i < n; ++i) cin >> a[i];
for (int i = 0; i < n; ++i) dp[i] = a[i];
for (int i = 0; i < n; ++i){
for (int j = 0; j < i; ++j){
if (a[j] < a[i]) dp[i] = max(dp[i], dp[j] + a[i]);
ans = max(ans, dp[i]);
}
}
cout << ans << '\n';
}
return 0;
}