http://acm.hdu.edu.cn/showproblem.php?pid=1003

동적 계획 문제.
#include<iostream>
#include<string.h>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main()
{  
    int n;
    int T;
    scanf("%d",&T);
    for(int k=1;k<=T;++k)
    {  printf("Case %d:
",k); scanf("%d",&n); int s=1,e=1,t=1; int maxx=-1000,sum=0; int a; for(int i=1;i<=n;++i) { scanf("%d",&a); sum+=a; if(sum>maxx) { maxx=sum; s=t; e=i; } if(sum<0) { sum=0; t=i+1; } } cout<<maxx<<" "<<s<<" "<<e<<endl; if(k!=T) cout<<endl; }return 0; }

좋은 웹페이지 즐겨찾기