Super Jumping! Jumping! Jumping! HDU - 1087
题意:
给你一个序列,要你求最大子序列和。
且子序列里,要严格单调递增。
思路:
最长上升子序列的O( n 2 n^2 n2)改一下即可.
AC
/*
皮卡丘冲鸭!
へ /|
/\7 ∠_/
/ │ / /
│ Z _,< / /`ヽ
│ ヽ / 〉
Y ` / /
イ● 、 ● ⊂⊃〈 /
() へ | \〈
>ー 、_ ィ │ //
/ へ / ノ<| \\
ヽ_ノ (_/ │//
7 |/
>―r ̄ ̄`ー―_
*/
#include <iostream>
#include <cmath>
#include <cstdio>
#include <algorithm>
#define For(i,x,y) for(int i=(x); i<=(y); i++)
#define fori(i,x,y) for(int i=(x); i<(y); i++)
#define rep(i,y,x) for(int i=(y); i>=(x); i--)
#define mst(x,a) memset(x,a,sizeof(x))
#define pb push_back
#define sz(a) (int)a.size()
#define ALL(x) x.begin(),x.end()
#define mp make_pair
#define fi first
#define se second
#define db double
#define debug(a) cout << #a << ": " << a << endl
using namespace std;
typedef long long LL;
typedef long long ll;
typedef unsigned long long ULL;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
typedef pair<int,int>pa;
typedef pair<ll,ll>pai;
typedef pair<db,db> pdd;
const int N = 2e5+10;
const int M = 1e5;
const int maxn=1e6+10;
const db eps = 1e-8;
const db pi = acos(-1.0);
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
long long dp[1100];
int a[1100];
int n;
void sol(){
For(i,1,n) scanf("%d", a+i);
For(i,1,n){
dp[i] = a[i];
For(j,1,i-1) if(a[i]>a[j]) dp[i]=max(dp[i],dp[j]+a[i]);
}
printf("%d\n", *max_element(dp+1,dp+1+n));
}
int main()
{
//ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
while(scanf("%d", &n)&&n){
sol();
}
return 0;
}