Digress:Although it is a simple question, the more inconspicuous things are often something we ignore, but it has a non-general importance. There was nothing in the city competition, and nothing in the provincial competition. Let me return to 0. So we should start from 0 and prepare for the next year and the last year. Let's not talk about it.
Analysis: this is a question that can be used in many ways. Although I used it in the past, I used violence in my memory. Today I want to use DP, which is also the preparation for the next question.
If f (I) is set, it indicates the maximum subsequence sum between the 1st-bit and the I-bit in the sequence, sum is the sum (different from the largest subsequence and) from the beginning of a bit to the first I-1 bit, And a is the number of columns in the original sequence.
F (I) = max {f (I-1), A (I) + (sum <0? 0: Sum )}
CodeIt can be further optimized, but I didn't think so, because we can see the shadows of this question in the next question.
Specifically, the introduction of a negative infinity point in The 0th bits does not affect the result, so that the two for s can be changed to one for S.
Code
# Include < Iostream >
Using Namespace STD;
Int DP [ 100001 ], [ 100001 ], Start [ 100001 ], End [ 100001 ];
Int Main ()
{
Int CAS;
CIN > CAS;
DP [ 0 ] = A [ 0 ] =- 10000 ;
For ( Int T = 1 ; T <= CAS; ++ T)
{
Int N, Sum = 0 , Temp = 1 ;
CIN > N;
For ( Int I = 1 ; I <= N; ++ I)
{
CIN > A [I];
If (DP [I - 1 ] > A [I] + Sum)
{
DP [I] = DP [I - 1 ];
Start [I] = Start [I - 1 ];
End [I] = End [I - 1 ];
}
Else
{
DP [I]=A [I]+SUM;
Start [I]=Temp;
End [I]=I;
}
Sum + = A [I];
If (Sum < 0 )
{
Sum= 0;
Temp=I+1;
}
}
Cout < " Case " < T < " : " < Endl;
Cout < DP [N] < " " < Start [N] < " " < End [N] < Endl;
If (T ! = CAS)
Cout < Endl;
}
Return 0 ;
}