简单吧。
1 #include <iostream> 2 #include <cstring> 3 using namespace std; 4 typedef long long ll; 5 6 const int N = 1001; 7 ll f1[N], f2[N]; 8 9 int main() { 10 int n; 11 while (cin >> n&&n != 0) { 12 for (int i = 0; i < n; i++) 13 cin >> f1[i]; 14 15 memset(f2, 0, sizeof(f2)); 16 17 f2[0] = f1[0]; 18 int nmax = 0; 19 for (int i = 1; i < n; i++) { 20 int temp = 0; 21 for(int j=0;j<i;j++) 22 if (f1[j] < f1[i] && temp < f2[j]) { 23 temp = f2[j]; 24 } 25 f2[i] = temp + f1[i]; 26 if (nmax < f2[i]) 27 nmax = f2[i]; 28 } 29 cout << nmax << endl; 30 } 31 }