悬赏关注

P1216 [USACO1.5] [IOI1994]数字三角形 Number Triangles

ddxdd @ 2024-08-15 15:13:25

#include<bits/stdc++.h>
using namespace std;
int n,ma;
int a[110][110],d[110][110];
/*void dfs(int x,int y,int sum){
    if(x<=n){
    ma=max(ma,sum);
        dfs(x+1,y,sum+a[x+1][y]);
        dfs(x+1,y+1,sum+a[x+1][y+1]);
    }

}*/
void dp(){
    for(int i=1;i<=n;i++){
        d[n][i]=a[n][i];
    }
    for(int i=n-1;i>=1;i--){
        for(int j=1;j<=i;j++){
            d[i][j]=a[i][j]+max(d[i+1][j],d[i+1][j+1]);
        }
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=i;j++){
            cin>>a[i][j];
        }
    }
    //dfs(1,1,a[1][1]);
    //cout<<ma;
    dp();
    cout<<d[1][1];
    return 0;
}

55分,wa求大佬


by Hyper_zero @ 2024-08-15 15:17:27

数组开小了


by Hyper_zero @ 2024-08-15 15:17:52

@ddxdd qwq


by ddxdd @ 2024-08-15 15:19:37

@Hyper_zero 感谢,已关注


|