ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1013. K-based Numbers. Version 3

Help! I Use this program to AC 1009, but can't AC this!
Posted by Dr.J.Pascal 13 Oct 2002 10:45
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!
Posted by Dr.J.Pascal 13 Oct 2002 10:51
> 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.
Posted by Leo 20 Nov 2002 13:19
try
mx=120
You have to small constants, defining the size of the numbers.
Posted by Leo 20 Nov 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.
Posted by David Beckham 19 Aug 2004 12:04
N+K<=1800 not 180