3. 找金币

program ex_3_1;
var
        t, max, n, i, j : integer;
        a : array[1 .. 2, 1 .. 60] of integer;
        noswap : boolean;
begin
        readln(n);
        for i := 1 to n do
            for j := 1 to i do
                read(a[i, j]);
        for i := 2 to n do
            for j := 1 to i do
                if (a[i-1, j] >= a[i-1, j-1]) and (a[i-1, j] >= a[i-1, j+1]) then
                     a[i, j] := a[i, j] + a[i-1, j]
                else if a[i-1, j-1] >= a[i-1, j+1] then
                     a[i, j] := a[i, j] + a[i-1, j-1]
                else
                     a[i, j] := a[i, j] + a[i-1, j+1];
        max := a[n, 1];
        for i := 1 to n do
            if a[n, i] > max then
               max := a[n, i];

        writeln;
        writeln(max);
        readln;
        readln;
end.


program ex_3_2;
var
        t, max, n, i, j : integer;
        a : array[1 .. 2, 1 .. 60] of integer;
        noswap : boolean;
begin
        readln(n);
        for i := 1 to n do
            for j := 1 to i do
            begin
                read(a[i, j]);
                if (a[i-1, j] >= a[i-1, j-1]) and (a[i-1, j] >= a[i-1, j+1]) then
                     a[i, j] := a[i, j] + a[i-1, j]
                else if a[i-1, j-1] >= a[i-1, j+1] then
                     a[i, j] := a[i, j] + a[i-1, j-1]
                else
                     a[i, j] := a[i, j] + a[i-1, j+1];
            end;
        max := a[n, 1];
        for i := 1 to n do
            if a[n, i] > max then
               max := a[n, i];

        writeln;
        writeln(max);
        readln;
        readln;
end.
posted @ 2010-03-04 14:52  SmartIOI  阅读(185)  评论(0)    收藏  举报
本站采用CC授权如需转载、引用文章,请务必附上作者及来源处。 Creative Commons License