Skip to content

Instantly share code, notes, and snippets.

@bojieli
Created October 27, 2014 12:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bojieli/05b2574e45a87d2e9adb to your computer and use it in GitHub Desktop.
Save bojieli/05b2574e45a87d2e9adb to your computer and use it in GitHub Desktop.
Project Euler #18
#include<stdio.h>
#define N 15
int main() {
int i, j, max = 0;
int a[N][N];
for (i=0; i<N; i++)
for (j=0; j<=i; j++)
scanf("%d", &a[i][j]);
for (i=1; i<N; i++) {
a[i][0] += a[i-1][0];
a[i][i] += a[i-1][i-1];
for (j=1; j<i; j++)
a[i][j] += (a[i-1][j] > a[i-1][j-1] ? a[i-1][j] : a[i-1][j-1]);
}
for (j=0; j<N; j++)
if (a[N-1][j] > max)
max = a[N-1][j];
printf("%d\n", max);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment