Skip to content

Instantly share code, notes, and snippets.

@yeopgi
Created August 28, 2021 05:30
Show Gist options
  • Save yeopgi/83651a8484b801e7abc4eac245054904 to your computer and use it in GitHub Desktop.
Save yeopgi/83651a8484b801e7abc4eac245054904 to your computer and use it in GitHub Desktop.
#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