标签:
Input
Output
Sample Input
3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
Sample Output
4 10 3
#include <iostream> #include <stdio.h> #include <algorithm> using namespace std; const int maxn=1002; int num[maxn],sum[maxn]; int main() { int n,i,j,ans; while(scanf("%d",&n)!=EOF&&n) { for(i=1;i<=n;i++) scanf("%d",&num[i]); sum[1]=num[1]; ans=sum[1]; for(i=2;i<=n;i++) { sum[i]=num[i]; for(j=1;j<i;j++) { if(num[j]<num[i]&&sum[j]+num[i]>sum[i]) sum[i]=sum[j]+num[i]; } if(ans<sum[i]) ans=sum[i]; } printf("%d\n",ans); } return 0; }
Super Jumping! Jumping! Jumping!
标签:
原文地址:http://www.cnblogs.com/lsb666/p/5767274.html