标签:rom each img everyone mini chess mina hdu http
InputInput contains multiple test cases. Each test case is described in a line as follow:
N value_1 value_2 …value_N
It is guarantied that N is not more than 1000 and all value_i are in the range of 32-int.
A test case starting with 0 terminates the input and this test case is not to be processed.
OutputFor each case, print the maximum according to rules, and one line one case.
Sample Input
3 1 3 2 4 1 2 3 4 4 3 3 2 1 0
Sample Output
4 10 3
1 #include<stdio.h> 2 #include<iostream> 3 #include<algorithm> 4 using namespace std; 5 const int MAX = 1005; 6 int main() 7 { 8 int num[MAX],sum[MAX],n,ans; 9 while(cin>>n&& n) 10 { 11 for(int i = 1; i <= n; i++) 12 cin>>num[i]; 13 sum[1] = num[1]; 14 ans = sum[1]; 15 for(int i = 2; i <= n; i++) 16 { 17 sum[i] = num[i]; 18 for(int j = 1; j <= i; j++) 19 { 20 if(num[j] < num[i]&&sum[j] +num[i]>sum[i]) 21 sum[i] = sum[j] + num[i]; 22 } 23 if(ans<sum[i]) 24 ans = sum[i]; 25 } 26 cout<<ans<<endl; 27 } 28 29 return 0; 30 }
Super Jumping! Jumping! Jumping!
标签:rom each img everyone mini chess mina hdu http
原文地址:http://www.cnblogs.com/jj81/p/7267825.html