1 solutions

  • 0
    @ 2026-11-13 19:57:16

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    
    int main() {
        int n;
        cin >> n;
    
        int a[105][105] = {0};
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                cin >> a[i][j];
            }
        }
    
        // 从下往上递推
        for (int i = n; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                a[i][j] += max(a[i+1][j], a[i+1][j+1]);
            }
        }
    
        cout << a[1][1] << endl;
        return 0;
    }
    
    • 1

    Information

    ID
    102
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By