Triangle

//120. Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.

For example, given the following triangle
[
[2],
[3,4],
[6,5,7],
[4,1,8,3]
]
The minimum path sum from top to bottom is 11 (i.e., 2 + 3 + 5 + 1 = 11).

#include 
#include 
#include 
#pragma GCC diagnostic error "-std=c++11"
using namespace std;

class Solution {
public:
    int minimumTotal(vector>& triangle) {
        assert(triangle.size()>0);

        int m=triangle.size();
        vector> dp(m,vector(m,triangle[0][0]));

        //i begin 1 i-1 != -1
        for(int i=1;i vec1(arr1,arr1+sizeof(arr1)/sizeof(int));
    vector vec2(arr2,arr2+sizeof(arr2)/sizeof(int));
    vector vec3(arr3,arr3+sizeof(arr3)/sizeof(int));
    vector vec4(arr4,arr4+sizeof(arr4)/sizeof(int));

    vector> triangle;
    triangle.push_back(vec1);
    triangle.push_back(vec2);
    triangle.push_back(vec3);
    triangle.push_back(vec4);

    cout<

你可能感兴趣的:(Triangle)