26 子数组的最大累加和问题
Table of Contents

ac(简单的动归)

import java.util.Scanner;


public class Main {

    public static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i ++){
            arr[i] = sc.nextInt();
        }
        int[] dp = new int[n];
        dp[0] = arr[0];
        int ans = dp[0];
        for(int i=1;i<n;i++){
            dp[i] = Math.max(dp[i-1] + arr[i], arr[i]);
            if(dp[i] > ans){
                ans = dp[i];
            }
        }
        System.out.println(ans);
    }

}
/*
7
1 -2 3 5 -2 6 -1

12
*/