View Code of Problem 65

#include <iostream>
#include "vector"

using namespace std;

/**
 * kkmd66 四刷
 * @return 
 */
int main() {

    int T;
    cin >> T;
    while (T--) {
        int R;
        cin >> R;
        //收集
        vector<vector<int>> matrix(R);
        for (int i = 0; i < R; ++i) {
            for (int j = 0; j < i + 1; ++j) {
                int temp;
                cin >> temp;
                matrix[i].push_back(temp);
            }
        }
        //找最优
        for (int i = R - 1; i > 0; --i) {
            for (int j = 0; j < i; ++j) {
                matrix[i][j] > matrix[i][j + 1] ? matrix[i - 1][j] += matrix[i][j] : matrix[i - 1][j] += matrix[i][j +
                                                                                                                   1];
            }
        }
        //输出
        cout << matrix[0][0] << endl;
    }

    return 0;
}

Double click to view unformatted code.


Back to problem 65