#1003 Max Sum,

Source: Internet
Author: User

#1003 Max Sum,

Http://acm.hdu.edu.cn/showproblem.php? Pid = 1, 1003

Here is a series for you to find out.A continuous subseriesAndThe sum of all numbers in this subseries is the largest.And output the sum, start, and end numbers of the subsequence.

I will not repeat the details here. Just look at the original question.

To be honest, I think this question is a little difficult... I have been thinking for a long time and I'm not smart enough...

However, the actual code is quite simple, and the main logic is in the two if in the middle. You can understand it with a closer look.

#include<stdio.h>#include<string.h>int main(){    int lop, test_case, test_case_timer = 0;    int input_count, number[100000];    int max, first, last, temp, sum;    scanf("%d", &test_case);    while (test_case_timer < test_case)    {        memset(number, 0, sizeof(number));        first = 0;        last = 0;        temp = 0;        sum = 0;        max = -1001;        scanf("%d", &input_count);        for (lop = 0; lop < input_count; lop++)        {            scanf("%d", &number[lop]);            sum += number[lop];            if (sum > max)            {                max = sum;                first = temp;                last = lop;            }            if (sum < 0)            {                sum = 0;                temp = lop + 1;            }        }        printf("Case %d:\n", test_case_timer+1);        printf("%d %d %d\n", max, first + 1, last + 1);        if (++test_case_timer != test_case)        {            printf("\n");        }    }    return 0;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.