继续前面没过去的那个动态规划题目,换了种简单的方法,姑且是过了,而且效率更高。(problem 1003)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int cnt = 1;
while (t-- > 0) {
int sum = 0;
int maxNum = -1001;
int start = 1, end = 1, temp = 1;
int[] arr = new int[100001];
int n = sc.nextInt();
for (int i=1; i<=n; i++) {
arr[i] = sc.nextInt();
sum += arr[i];
if (sum > maxNum) {
maxNum = sum;
start = temp;
end = i;
}
if (sum < 0) {
temp = i + 1;
sum = 0;
}
}
System.out.println("Case " + cnt++ + ":");
System.out.println(maxNum + " " + start + " " + end);
if (t > 0) {
System.out.println();
}
}
}
}