Why My Program Get Crash(ACCESS_VIOLATION) ? Help !!!
Posted by
XueMao 31 Jul 2002 17:40
{$N+,s-}
Program Lucky_ticket;
Type xm=array[-50..200] of integer;
Lion=array[0..1,-50..1000] of ^xm;
Var k,i,j,m,n,u,v,t,t1:Longint;
q:double;
a:Lion;
LL:array[0..1,-100..1000] of integer;
c:array[-100..1000] of longint;
Procedure Go(x,y:longint);
var i,j,k,L:longint;
begin
if LL[t,x]>LL[t1,y] then L:=LL[t,x]
else L:=LL[t1,y];
for i:=1 to L do
begin
inc(a[t,x]^[i],a[t1,y]^[i]);
if a[t,x]^[i]>9 then
begin
dec(a[t,x]^[i],10);
inc(a[t,x]^[i+1]);
end;
end;
if a[t,x]^[L+1]<>0 then LL[t,x]:=L+1
else LL[t,x]:=L;
end;
Procedure Cheng(x:integer);
var i,L:longint;
begin
fillchar(c,sizeof(c),0);
for i:=1 to LL[t,x] do
for j:=1 to LL[t,x] do
inc(c[i+j-1],a[t,x]^[i]*a[t,x]^[j]);
for i:=1 to LL[t,x]+LL[t,x] do
begin
inc(c[i+1],c[i] div 10);
c[i]:=c[i] mod 10;
end;
if c[LL[t,x]+LL[t,x]]<>0 then L:=LL[t,x]+LL[t,x]
else L:=LL[t,x]+LL[t,x]-1;
for i:=L downto 1 do
write(c[i]);
writeln;
end;
Begin
read(n);
read(m);
if (m>2*n*9)or(odd(m)) then
begin
writeln(0);
exit;
end;
m:=m shr 1;
for j:=0 to 1 do
for i:=0 to m+1 do
begin
new(a[j,i]);
fillchar(a[j,i]^,sizeof(a[j,i]^),0);
end;
for i:=0 to 9 do
begin
a[1,i]^[1]:=1;
LL[1,i]:=1;
end;
t:=1;
t1:=0;
for i:=2 to n do
begin
t1:=t;
t:=1-t;
for j:=0 to m+1 do
fillchar(a[t,j]^,sizeof(a[t,j]^),0);
fillchar(LL[t],sizeof(LL[t]),0);
u:=i*9;
if m<u then u:=m;
for j:=0 to u do
begin
v:=j-9;
if v<0 then v:=0;
for k:=v to j do
go(j,k);
end;
LL[t1]:=LL[t];
end;
cheng(m);
End.