Created
August 28, 2021 05:30
-
-
Save yeopgi/83651a8484b801e7abc4eac245054904 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int Max(int a, int b) { return a > b ? a : b; } | |
int main() { | |
int i, j, n, max = 0, d[501][501] = {0}; | |
scanf("%d", &n); | |
for (i = 1; i <= n; i++) | |
for (j = 1; j <= i; j++) { | |
scanf("%d", &d[i][j]); | |
if (j == 1) | |
d[i][j] = d[i - 1][j] + d[i][j]; | |
else if (j == i) | |
d[i][j] = d[i - 1][j - 1] + d[i][j]; | |
else | |
d[i][j] = Max(d[i - 1][j - 1], d[i - 1][j]) + d[i][j]; | |
if (max < d[i][j]) | |
max = d[i][j]; | |
} | |
printf("%d", max); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment