class Solution {
public:
int minimumTotal(vector<vector<int>>& tr) {
int n = tr.size();
vector<vector<int>> f(n+1, vector<int>(n+1));
for(int i = n-1; i >= 0; i--)
for(int j = 0; j <= i; j++)
f[i][j] = min(f[i+1][j], f[i+1][j+1]) + tr[i][j];
return f[0][0];
}
};