一个最长上升子序列,只不过把长度换成和。
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
ll num[1005],dp[1005];
int n;
int main()
{
while(~scanf("%d",&n) && n)
{
memset(dp,0,sizeof dp);
for (int i = 0; i < n; i++)
{
scanf("%d",&num[i]);
}
int ans = 0;
for (int i = 0; i < n; i++)
{
dp[i] = num[i];
for (int j = 0; j < i; j++)
{
if(num[j] < num[i] && dp[j] + num[i] > dp[i])
dp[i] = dp[j] + num[i];
}
}
for (int i = 0; i < n; i++)
{
if(ans < dp[i])
ans = dp[i];
}
printf("%d\n",ans);
}
}