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 1054. Tower of Hanoi

How to find impossible sequense
Posted by Juri Krainjukov 3 Dec 2002 03:38
I've written program that finds the number of steps but Can't
determine whether it's possible or not.

var
   N:integer;
   s,d:array[1..31] of integer;
   i,j,t:integer;
   K:longint;
   n2:array[0..30] of longint;

begin

   readln(N);
   for I:=1 to n do read(s[i]);
   n2[0]:=1;
   for I:=1 to 30 do n2[i]:=n2[i-1]*2;
   for I:=1 to n do d[i]:=1;

   k:=0;
   for I:=n downto 1 do
   begin
      IF D[I]<>S[I] then
      begin
          K:=K+N2[i-1];
         for j:=1 to 3 do if (s[i]<>j) and (d[i]<>j) then
         begin
            t:=j;
            break;
         end;
         for J:=1 to i-1 do if d[j]=d[i] then
         begin
            d[j]:=t;
         end;
         d[i]:=s[i];
         end;
   end;
    writeln(k);

end.