P1044 - 数字三角形From Admin Normal (OI)总时限:10s 内存限制:128MB 代码长度限制:64KB | ||||||||
---|---|---|---|---|---|---|---|---|
|
动规。数字三角形,最简单的那种。
1 program p1044; 2 3 var n,x,y:integer; 4 5 a:array[1..30,1..30,1..4]of integer; 6 7 begin 8 9 readln(n); 10 11 for x:=1 to n do 12 13 begin 14 15 for y:=1 to x do 16 17 begin 18 19 read(a[x,y,1]); 20 21 a[x,y,2]:=a[x,y,1]; 22 23 a[x,y,3]:=0; 24 25 end; 26 27 readln; 28 29 end; 30 31 for x:=n-1 downto 1 do 32 33 for y:=1 to n do 34 35 if a[x+1,y,2]>a[x+1,y+1,2] 36 37 then 38 39 a[x,y,2]:=a[x,y,2]+a[x+1,y,2] 40 41 else 42 43 a[x,y,2]:=a[x,y,2]+a[x+1,y+1,2]; 44 45 writeln(a[1,1,2]); 46 47 readln; 48 49 readln; 50 51 end.
原文:http://www.cnblogs.com/111qqz/p/4296130.html