View Code of Problem 19

#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1010;
int A[maxn],dp[maxn];
int main(){
	int n;
	while(cin>>n){
		if(n==0){
			break;
		} 
		//输入序列 
	for(int i=0;i<n;i++){
		scanf("%d",&A[i]);
	}
	//然后进行动态规划
	dp[0]=A[0];
	for(int i=1;i<n;i++){
		dp[i]=max(A[i],dp[i-1]+A[i]);
	} 
	sort(dp,dp+n);
	cout<<dp[n-1]<<endl;
	}
	
	  return 0;
    }

Double click to view unformatted code.


Back to problem 19