-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheuler67.c
61 lines (50 loc) · 925 Bytes
/
euler67.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include<stdio.h>
#include<string.h>
#define NN 99
int a[101][101],count=0,memo[101][101];
int max(int a,int b)
{
return a>b?a:b;
}
int maxx(int a,int b,int c)
{
return max(max(a,b),c);
}
/*
int calc(int i,int j,int sum)
{
if(i==NN+1&&j<=i){
count++;
return sum;
}
if(i<0||j<0||i>NN||j>i)
return 0;
if(memo[i][j]==-1){
// printf("%d ",a[i][j]);
sum+=a[i][j];
memo[i+1][j]=calc(i+1,j,sum);
memo[i+1][j+1]=calc(i+1,j+1,sum);
memo[i][j]=max(memo[i+1][j],memo[i+1][j+1]);
}
return memo[i][j];
}
*/
int main()
{
int i,j;
memset(memo,-1,sizeof(memo));
for(i=0;i<=NN;i++)
{
for(j=0;j<=i;j++)
scanf("%d",&a[i][j]);
}
for(i=NN-1;i>=0;i--)
{
for(j=0;j<=i;j++){
//printf("%d %d %d\n",a[i][j],a[i+1][j],a[i+1][j+1]);
a[i][j]+=max(a[i+1][j],(j+1<=i+1?a[i+1][j+1]:0));
}
}
printf("%d\n",a[0][0]);
return 0;
}