http://noi.openjudge.cn/ch0206/3532/
改一下最长上升子序列的程序就行了,f[i]记录以i结尾的最大上升子序列和
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define ms(i,j) memset(i, j, sizeof(i));
using namespace std;
int n;
int a[1005];
int f[1005];
int main()
{
scanf("%d", &n);
for (int i=1;i<=n;i++) scanf("%d", &a[i]);
ms(f,0);
int orz = 0;
for (int i=1;i<=n;i++)
{
f[i] = a[i];
for (int j=1;j<i;j++)
{
if (a[j]<a[i])
{
f[i] = max(f[i], a[i]+f[j]);
}
}
orz = max(orz, f[i]);
}
printf("%d\n", orz);
return 0;
}