input:
3 1 3 2
4 1 2 3 4
4 3 3 2 1
0
output:
4
10
3
题目大意:
寻找严格递增的序列和。
分析:
LIS。dp[i]表示前i个最长递增序列和。
code:
#define frp
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 0x3f3f3f3f;
const ll inf = 0x7fffff;
const int maxn = 1 << 15;
const int MAXN = 10000;
int dp[1001];
int n, chess[1001];
void solve() {
while (cin >> n&&n) {
for (int i = 0; i < n; i++) {
cin >> chess[i];
}
int ans = 0;
for (int i = 0; i < n; i++) {
dp[i] = chess[i];
for (int j = 0; j < i; j++) {
if (chess[i] > chess[j]) {
dp[i] = max(dp[i], dp[j] + chess[i]);
}
}
ans=max(ans,dp[i]);
}
cout << ans << endl;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifdef frp
freopen("D:\\coding\\c_coding\\in.txt", "r", stdin);
// freopen("D:\\coding\\c_coding\\out.txt", "w", stdout);
#endif
solve();
return 0;
}