cKK

............当你觉得自己很辛苦,说明你正在走上坡路.............坚持做自己懒得做但是正确的事情,你就能得到别人想得到却得不到的东西............

导航

(DP)MaxSubArr

Posted on   cKK  阅读(199)  评论(0编辑  收藏  举报
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public static int MSA(int[] ar) {
        int[] arr = new int[ar.length];
        int msa = 0;
        arr[0] = ar[0];
        for (int i = 1; i < ar.length; i++) {
            if (arr[i-1]>= 0)
                arr[i] = arr[i - 1] + ar[i];
            else
                arr[i] = ar[i];
        }
        for (int i=0;i<ar.length;i++) {
            System.out.println(arr[i]);
            if (arr[i] > msa)
                msa = arr[i];
        }
        return msa;
    }

  

努力加载评论中...
点击右上角即可分享
微信分享提示