#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;}