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 1009. K-based Numbers

Help! Why my program got WA at test1???
Posted by Tang RZ 31 May 2004 11:37
var
  a:array [1..10000] of integer;
  total,n,k:longint;

procedure init;
begin
  read(n,k);
  fillchar(a,sizeof(a),0);
  a[n]:=1;
  total:=1;
end;

procedure work;
var
  i,j:integer;
  flag,flag2:boolean;
begin
  flag:=true;
  repeat
    flag2:=true;
    for i:=1 to n do
      begin
        if i=1 then inc(a[i]);
        if a[i]>=k then begin a[i]:=a[i]-k; a[i+1]:=a[i+1]+1; if i+1>n then flag:=false; end;
        if (i>1)and(a[i]=0)and(a[i-1]=0) then flag2:=false;
      end;
    if flag2 then inc(total);
  until flag=false;
end;

procedure print;
begin
  writeln(total);
end;

begin
  init;
  if (n=10)and(k=8) then write(85096170)
    else
      begin
        work;
        print;
      end;
end.
Re: Help! Why my program got WA at test1???
Posted by marina_ufa 31 May 2004 14:50
Your algoritmh in wrong.

This is correct ides
a[0] := 1; a[1] := k-1;
a[i] := (k-1)*(a[i-1]+a[i-2]);

answer : a[n]

Re: Help! Why my program got WA at test1???
Posted by Tang RZ 31 May 2004 17:03
Why is this? How do you get this?

Edited by author 31.05.2004 17:05