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

WA 1
Posted by Komand_0 11 Jan 2014 17:46
var n,k,tc:integer;
    a:array [1..20] of integer;
procedure gen(x:integer);
 var i:integer;
 begin
   if x = n+1 then
      inc(tc)
   else
    begin
    if x=1 then
           for i:=1 to k-1 do
       begin
       a[x]:=i;
       gen(x+1);
       end
    else
     for i:=0 to k-1 do
       begin
       a[x]:=i;
       if (a[x-1]=0) then
       begin
        if (i=0) then
           begin
              inc(x);
              dec(x);
           end;
        end
        else
            gen(x+1);
       end;
    end;
 end;
 begin
  readln(n);
  readln(k);
  gen(1);
  writeln(tc);
 end.
What is it!