#include <stdio.h>
int num[501][501];
int dp[501][501];
int max(int a,int b) {
    return a>b? a:b;
}
int bottom_up(int n) {
    //기저
    dp[1][1]=num[1][1];
    int res=0;
    for(int i=2; i<=n; i++) {
        for(int j=1; j<=i; j++) {
            dp[i][j]=max(dp[i-1][j]+num[i][j],dp[i-1][j-1]+num[i][j]);     
        }
    }
    for(int i=1; i<=n; i++) {
        res=max(dp[n][i],res);
    }
    return res;
}

int main() {
    int n;
    scanf("%d",&n);
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=i; j++) {
            scanf("%d",&num[i][j]);
        }
    }
    printf("%d",bottom_up(n));
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: