@@ -0,0 +1,1880 @@
+package com.zhangjikai.dp;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0A%0A/**%0A * Created by Jikai Zhang on 2017/5/22.%0A */%0Apublic class Triangle %7B%0A%0A    public int minimumTotal(List%3CList%3CInteger%3E%3E triangle) %7B%0A%0A        if (triangle == null %7C%7C triangle.size() == 0) %7B%0A            return 0;%0A        %7D%0A%0A        if (triangle.size() == 1) %7B%0A            return triangle.get(0).get(0);%0A        %7D%0A%0A        int size = triangle.size();%0A        int%5B%5D%5B%5D matrix = new int%5Bsize%5D%5Bsize%5D;%0A        matrix%5B0%5D%5B0%5D = triangle.get(0).get(0);%0A%0A        List%3CInteger%3E list;%0A        for (int i = 1; i %3C size; i++) %7B%0A            list = triangle.get(i);%0A%0A            matrix%5Bi%5D%5B0%5D = matrix%5Bi - 1%5D%5B0%5D + list.get(0);%0A%0A            for (int j = 1; j %3C list.size() - 1; j++) %7B%0A                matrix%5Bi%5D%5Bj%5D = Math.min(matrix%5Bi - 1%5D%5Bj - 1%5D, matrix%5Bi - 1%5D%5Bj%5D) + list.get(j);%0A            %7D%0A%0A            matrix%5Bi%5D%5Blist.size() - 1%5D = matrix%5Bi - 1%5D%5Blist.size() - 2%5D + list.get(list.size() - 1);%0A        %7D%0A%0A        int lastRow = size - 1;%0A        int min = matrix%5BlastRow%5D%5B0%5D;%0A        for (int i = 1; i %3C matrix%5BlastRow%5D.length; i++) %7B%0A            if (matrix%5BlastRow%5D%5Bi%5D %3C min) %7B%0A                min = matrix%5BlastRow%5D%5Bi%5D;%0A            %7D%0A        %7D%0A%0A        return min;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A        List%3CList%3CInteger%3E%3E allList = new ArrayList%3C%3E();%0A        List%3CInteger%3E list = new ArrayList();%0A        list.add(2);%0A        allList.add(list);%0A        list = new ArrayList%3C%3E();%0A        list.add(3);%0A        list.add(4);%0A        allList.add(list);%0A        list = new ArrayList%3C%3E();%0A        list.add(6);%0A        list.add(5);%0A        list.add(7);%0A        allList.add(list);%0A%0A        list = new ArrayList%3C%3E();%0A        list.add(4);%0A        list.add(1);%0A        list.add(8);%0A        list.add(3);%0A        allList.add(list);%0A%0A        System.out.println(new Triangle().minimumTotal(allList));%0A%0A%0A    %7D%0A%7D%0A

add Triangle