There are currently 2 posts.
Font size: Small - 100% (Default)  Content converter: No conversion
 
Clicks Replies
1113 1
【试题】算法训练 数字三角形
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 1 Posted at: 4/24/16 20:36
【得分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;
}
巨大八爪鱼
武林盟主 二十一级
Reply
Floor 2 Posted at: 4/24/16 20:37
评测结果  运行超时   得分  57  
CPU使用  运行超时  
内存使用  1.636MB  
Reply the post
Content:
User: You are currently anonymous.
Captcha:
Unclear? Try another one.
(Shortcut key: Ctrl+Enter)
Post Information
Clicks: 1113 Replies: 1
Author: 巨大八爪鱼
Last reply: 巨大八爪鱼
Last reply time: 4/24/16 20:37
Announcements