1 solutions

  • 0
    @ 2022-8-28 20:09:22

    线性dp问题

    #include<bits/stdc++.h>
    using namespace std;
    
    const int N=510;
    int f[N][N];
    int n;
    
    int main(){
        cin>>n;
        for(int i=1;i<=n;i++){
            for(int j=1;j<=i;j++){
                cin>>f[i][j];
            }
        }
    
        for(int i=n;i>=1;i--){
            for(int j=i;j>=1;j--){
                f[i][j]=max(f[i+1][j],f[i+1][j+1])+f[i][j];
            }
        }
        cout<<f[1][1]<<endl;
    }
    
    • 1

    Information

    ID
    6541
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    37
    Accepted
    20
    Uploaded By