Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const
- ikl=64;
- type
- pole=record
- x:integer;
- y:integer;
- end;
- type
- mas=array[1..ikl]of pole;
- Function obx(tek1:pole;proi:mas;sh:integer):boolean;
- var
- i:integer;
- tested:boolean;
- begin
- tested:=true;
- For i:=1 to sh do
- begin
- if proi[i]=tek1 then
- tested:=false;
- end;
- obx:=tested;
- end;
- Function shaq(tek,fin:pole;proi:mas;colv,sh:integer):integer;
- var
- sum:integer;
- tek1:pole;
- begin
- sum:=0;
- if (tek=fin)and(colv=0) then
- sum:=1
- else
- begin
- if colv>0 then
- begin
- proi[sh]:=tek;
- if tek.y +1 <=8 then
- begin
- tek1.x:=tek.x;
- tek1.y:=tek.y+1;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- if tek.y -1 >=1 then
- begin
- tek1.x:=tek.x;
- tek1.y:=tek.y-1;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- if tek.x + 1 <=8 then
- begin
- if tek.y +1<=8 then
- begin
- tek1.x:=tek.x +1;
- tek1.y:=tek.y +1;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- if tek.y -1 >= 1 then
- begin
- tek1.x:=tek.x +1;
- tek1.y:=tek.y -1;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- tek1.x:=tek.x+1;
- tek1.y:=tek.y;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- if tek.x - 1 >=1 then
- begin
- if tek.y +1<=8 then
- begin
- tek1.x:=tek.x -1;
- tek1.y:=tek.y +1;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- if tek.y -1 >= 1 then
- begin
- tek1.x:=tek.x -1;
- tek1.y:=tek.y -1;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- tek1.x:=tek.x-1;
- tek1.y:=tek.y;
- if obx(tek1,proi,sh) then
- sum:=sum+shaq(tek1,fin,proi,colv-1,sh+1);
- end;
- end;
- end;
- shaq:=sum;
- end;
- var
- proi:mas;
- s,s1,alf:string;
- star,fin:pole;
- colv,colvsha:integer;
- begin
- alf:='ABCDEFGH';
- readln(s);
- s1:=copy(s,1,pos(' ',s)-1);
- delete(s,1,pos(' ',s));
- star.x:=pos(copy(s1,1,1),alf);
- star.y:=strtoint(copy(s1,2,1));
- s1:=copy(s,1,pos(' ',s)-1);
- delete(s,1,pos(' ',s));
- fin.x:=pos(copy(s1,1,1),alf);
- fin.y:=strtoint(copy(s1,2,1));
- colv:=strtoint(copy(s,1,1));
- colvsha:=shaq(star,fin,proi,colv,1);
- writeln(colvsha);
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement