HDOJ 1003

#include <iostream>

using namespace std;

int arr[100010];
int main()
{
int l;
cin>>l;
for(int j=0;j<l;j++)
{

    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>arr;

    int t=0,beginpos,endpos,max=-99999999,k=0;
    for(int i=0;i<n;i++)
    {
        t+=arr;
        if(t>max)
        {
            max=t;
            beginpos=k;
            endpos=i;
        }

        if(t<0)
        {
            t=0;
            k=i+1;
        }
    }
    cout<<"Case "<<j+1<<":\n";
    cout<<max<<" "<<beginpos+1<<" "<<endpos+1<<endl;
    if((j+1)!=l)  cout<<endl;
}
    return 0;

}


动态规划 
原文地址:https://www.cnblogs.com/CKboss/p/3351148.html