Super Jumping! Jumping! Jumping!
E - Super Jumping! Jumping! Jumping!
思路:就是按照求最长有序子序列的思路来写,跟Monkey and Banana的思路大同小异。
代码:
// Created by CAD on 2019/10/26.
#include <bits/stdc++.h>
using namespace std;
int dp[1005];
int a[1005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
while(cin>>n&&n)
{
int maxn=0;
for(int i=1;i<=n;++i)
cin>>a[i],dp[i]=a[i],maxn=max(maxn,a[i]);
for(int i=1;i<=n;++i)
for(int j=1;j<i;++j)
if(a[i]>a[j])
dp[i]=max(dp[i],dp[j]+a[i]),maxn=max(maxn,dp[i]);
cout<<maxn<<endl;
}
return 0;
}