Help! I Use this program to AC 1009, but can't AC this! program p1013; const mx=120; type arr=array[1..mx] of longint; var a:array[0..1800] of arr; n,k,k1,t,i,j:integer; begin readln(n); readln(k); fillchar(a,sizeof(A),0); k1:=k-1; t:=1; while k1>0 do begin a[1,t]:=k1 mod 10; k1:=k1 div 10; inc(t); end; a[0,1]:=1; for i:=2 to n do begin for j:=1 to mx do a[i,j]:=a[i,j]+a[i-1,j]+a[i-2,j]; for j:=1 to mx do a[i,j]:=a[i,j]*(k-1); for j:=1 to mx do a[i,j+1]:=a[i,j+1]+a[i,j] div 10; for j:=1 to mx do a[i,j]:=a[i,j] mod 10; end; i:=50; while a[n,i]=0 do dec(i); for j:=i downto 1 do write(a[n,j]); writeln; end. Re: Help! I Use this program to AC 1009, but can't AC this! > program p1013; > const mx=120; > type arr=array[1..mx] of longint; > var a:array[0..1800] of arr; > n,k,k1,t,i,j:integer; > > begin > readln(n); readln(k); > fillchar(a,sizeof(A),0); > k1:=k-1; t:=1; > while k1>0 do > begin > a[1,t]:=k1 mod 10; > k1:=k1 div 10; inc(t); > end; > a[0,1]:=1; > for i:=2 to n do > begin > for j:=1 to mx do a[i,j]:=a[i,j]+a[i-1,j]+a[i-2,j]; > for j:=1 to mx do a[i,j]:=a[i,j]*(k-1); > for j:=1 to mx do a[i,j+1]:=a[i,j+1]+a[i,j] div 10; > for j:=1 to mx do a[i,j]:=a[i,j] mod 10; > end; I think I typed a wrong sentence: > i:=mx; while a[n,i]=0 do dec(i); > for j:=i downto 1 do write(a[n,j]); > writeln; > end. You have to small constants, defining the size of the numbers. Послано Leo 20 ноя 2002 13:19 try mx=120 You have to small constants, defining the size of the numbers. Послано Leo 20 ноя 2002 13:20 Try to increase mx and don't use array a. You need only two last values. Re: You have to small constants, defining the size of the numbers. N+K<=1800 not 180 |