1 /**************************************************************
2 Problem: 1675
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:1860 ms
7 Memory:228 kb
8 ****************************************************************/
9
10 const
11 mx:array[1..4] of longint=(0,1,0,-1);
12 my:array[1..4] of longint=(1,0,-1,0);
13 var
14 i,j,k,l,m,n,ans,i1,i2,i3,i4,i5,i6,i7:longint;
15 ch:char;
16 map:array[0..6,0..6] of longint;
17 s:array[0..8] of longint;
18 function check:boolean;
19 var
20 i,j,sx,sy,xx,yy,sum,t,w:longint;
21 nx,ny:array[0..8] of longint;
22 q:array[0..10] of longint;
23 d:array[0..6,0..6] of longint;
24 begin
25 sum:=0;t:=0;w:=1;
26 fillchar(nx,sizeof(nx),0);
27 fillchar(ny,sizeof(ny),0);
28 fillchar(q,sizeof(q),0);
29 fillchar(d,sizeof(d),0);
30 for i:=1 to 7 do
31 begin
32 ny[i]:=s[i] mod 5;
33 nx[i]:=(s[i] div 5)+1;
34 if ny[i]=0 then
35 begin
36 ny[i]:=5;
37 dec(nx[i]);
38 end;
39 d[nx[i],ny[i]]:=i;
40 end;
41 q[1]:=1;d[nx[1],ny[1]]:=0;sum:=map[nx[1],ny[1]];
42 while t<w do
43 begin
44 inc(t);
45 xx:=nx[q[t]];
46 yy:=ny[q[t]];
47 for k:=1 to 4 do
48 begin
49 sx:=xx+mx[k];
50 sy:=yy+my[k];
51 if (sx<1) or (sy<1) or (sy>5) or (sy>5) or (d[sx,sy]=0) then continue;
52 inc(w);
53 q[w]:=d[sx,sy];
54 d[sx,sy]:=0;
55 inc(sum,map[sx,sy]);
56 end;
57 end;
58 exit((w=7) and (sum>3));
59 end;
60 begin
61 fillchar(map,sizeof(map),0);
62 for i:=1 to 5 do
63 for j:=1 to 5 do
64 begin
65 read(ch);
66 if ch=‘J‘ then map[i,j]:=1 else map[i,j]:=0;
67 if j=5 then readln;
68 end;
69 ans:=0;
70 for i1:=1 to 19 do
71 for i2:=i1+1 to 20 do
72 for i3:=i2+1 to 21 do
73 for i4:=i3+1 to 22 do
74 for i5:=i4+1 to 23 do
75 for i6:=i5+1 to 24 do
76 for i7:=i6+1 to 25 do
77 begin
78 s[1]:=i1;s[2]:=i2;s[3]:=i3;
79 s[4]:=i4;s[5]:=i5;s[6]:=i6;s[7]:=i7;
80 if check then inc(ans);
81 end;
82 writeln(ans);
83 readln;
84 end.