http://acm.hdu.edu.cn/showproblem.php?pid=1087
AC代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int value[1010];
int dp[1010];
int main()
{
int n,i,j,maxx,ma;
while(scanf("%d",&n)&&n)
{
for(i = 0; i < n; i++)
{
scanf("%d",&value[i]);
}
maxx = 0;
ma = dp[0] = value[0];
for(i = 0; i < n; i++)
{
ma = 0;
dp[i] = value[i];
for(j = 0; j < i; j++)
{
if(value[j]<value[i])
{
if(dp[j] > ma)
{
ma = dp[j];
}
}
}
dp[i] = dp[i] + ma;
if(dp[i] > maxx)
{
maxx = dp[i];
}
}
printf("%d\n",maxx);
}
return 0;
}