题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 using namespace std; 5 const int maxn=1010; 6 int dp[maxn],p[maxn]; 7 int n; 8 9 int main() 10 { 11 p[0]=-0x3f3f3f3f; 12 while(scanf("%d",&n)&&n) 13 { 14 int ans=-0x3f3f3f3f; 15 memset(dp,0,sizeof(dp)); 16 for(int i=1;i<=n;i++) 17 { 18 scanf("%d",&p[i]); 19 dp[i]=p[i]; 20 for(int j=0;j<i;j++) 21 if(p[j]<p[i]) 22 { 23 dp[i]=max(dp[i],dp[j]+p[i]); 24 ans=max(ans,dp[i]); 25 } 26 } 27 printf("%d ",ans); 28 29 } 30 }