View Code
#include <stdio.h> #include <string.h> #define N 1005 int dp[N], num[N]; int main() { int n; while(scanf("%d", &n), n) { memset(dp, 0, sizeof(dp)); for(int i = 0; i < n; ++i) scanf("%d", &num[i]); int max = 0; for(int i = 0; i < n; ++i) { dp[i] = num[i]; //若从 一开始就跳到 i for(int j = 0; j < i; ++j) { //若从i 之前的点 j 能跳到 i,则记录从 j跳到i 所能达到的最大值 if(num[i] > num[j] && dp[j] + num[i] > dp[i]) dp[i] = dp[j] + num[i]; if(max < dp[i]) //记录最大值 max = dp[i]; } } printf("%d\n", max); } }