标签:
#include <iostream> #include <fstream> #include <string> #include <cstring> using namespace std; const int MAX = 1001; int dp[MAX]; int a[MAX]; // 最大增序列 int main() { //fstream cin("aaa.txt"); int n; while(cin >> n) { if(!n) break; memset(dp, 0, sizeof(dp)); for(int i = 1; i <= n; i++) { cin >> a[i]; dp[i] = a[i]; } for(int i = 1; i <= n; i++) for(int j = 1; j < i; j++) if(a[j] < a[i] && dp[j] + a[i] > dp[i]) dp[i] = dp[j] + a[i]; int max = -1000001; for(int i = 1; i <= n; i++) if(dp[i] > max) max = dp[i]; cout << max << endl; } return 0; }
标签:
原文地址:http://www.cnblogs.com/lyf-acm/p/5434255.html