pascal编程问题,求大师解答给最简洁的程序!!

2024-11-22 20:53:39
推荐回答(2个)
回答(1):

既然1已经用来表示障碍,那就用-1表示有1种方案,-2表示有2种方案,……。
var a:array[0..100,0..100]of integer;
n,m,i,j:integer;
begin
read(m,n);
for i:=1 to m do
for j:=1 to n do
read(a[i,j]);
if a[1,1]=1 then begin writeln(0); exit end
else a[1,1]:=-1;
for i:=1 to m do
for j:=1 to n do
if a[i,j]=0 then
begin
if a[i-1,j]<0 then inc(a[i,j],a[i-1,j]);
if a[i,j-1]<0 then inc(a[i,j],a[i,j-1]);
end;
writeln(-a[m,n]);
end.

回答(2):

程序完成如下:
var a:array[0..10000]of integer;
n,i,x:integer;
begin
read(n);
for i:=1 to n do
begin
read(x);
inc(a[i]);
end;
for i:=0 to 10000 do
if a[i]>0 then writeln(i,' ',a[i]);
end.