hiho Week 5 register

Ended

Participants:445

Verdict:Accepted
Score:100 / 100
Submitted:2014-08-05 10:14:34

Lang:GCC

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <stdio.h>
int n,map[201][201],f[201][201];
int max_(int a,int b) {return a>b?a:b;}
int main(){
    int i,j;
    scanf("%d",&n);
    for (i=1;i<=n;i++)
        for (j=1;j<=i;j++) scanf("%d",&map[i][j]);
    for (i=1;i<=n;i++) f[n][i]=map[n][i];
    for (i=n-1;i>=1;i--)
        for (j=1;j<=i;j++) f[i][j]=max_(f[i+1][j],f[i+1][j+1])+map[i][j];
    printf("%d\n",f[1][1]);
    return 0;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX