【得分57】 #include <stdio.h> #include <stdlib.h>
int n; int max = 0; int **tree;
void find(int x, int y, int last) { if (y > x) return; last += tree[x][y]; if (x == n - 1) { if (max < last) max = last; return; } find(x + 1, y, last); find(x + 1, y + 1, last); }
int main() { int i, j; scanf("%d", &n); tree = (int **)malloc(n * sizeof(int **)); *tree = (int *)malloc((n + 1) * n / 2 * sizeof(int *)); for (i = 0; i < n; i++) { if (i > 0) tree[i] = tree[i - 1] + i; for (j = 0; j <= i; j++) scanf("%d", &tree[i][j]); } find(0, 0, 0); printf("%d\n", max); free(*tree); free(tree); return 0; }
|