HDU 1087 Super Jumping! Jumping! Jumping!
最长递增子序列
1 #include <iostream> 2 #include <vector> 3 #include <algorithm> 4 #include <cstring> 5 #define MAX 1001 6 using namespace std; 7 8 int dp[MAX]; 9 10 int main(){ 11 int n; 12 while(cin >> n && n){ 13 int player[MAX]; 14 for(int i = 1 ; i <= n ; i ++ ) cin >> player[i]; 15 memset(dp,0,sizeof(dp)); 16 17 int maxsum = 0; 18 for(int i = 1; i <= n; i ++ ){ 19 dp[i] = player[i]; 20 for(int j = 1; j < i ; j ++ ){ 21 if(player[i] > player[j]) 22 dp[i] = max(dp[i],dp[j] + player[i]); 23 } 24 maxsum = max(maxsum,dp[i]); 25 } 26 cout<<maxsum<<endl; 27 } 28 29 return 0; 30 }