1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <algorithm> 4 using namespace std; 5 int n; 6 int dp[1005],val[1005]; 7 8 int main() 9 { 10 while( scanf("%d",&n) && n ){ 11 for( int i=1 ; i<=n ; i++ ) 12 scanf("%d",&val[i]); 13 int Max; 14 Max = dp[1] = val[1]; 15 for( int i=1 ; i<=n ; i++ ){ 16 dp[i] = val[i]; 17 for( int j=1 ; j<i ; j++ ){ 18 if( val[i] > val[j] && dp[i] < dp[j]+val[i] ) 19 dp[i] = dp[j] + val[i]; 20 } 21 if( dp[i] > Max ) 22 Max = dp[i]; 23 } 24 printf("%d\n",Max); 25 } 26 return 0; 27 }
时间: 2024-12-16 15:05:43