|
对,只判断正左边和正上边的格子就可以了:
SQL>
SQL> with t as (select 'R' color from dual
2 union all
3 select 'Y' from dual
4 union all
5 select 'B' from dual),
6 s as (select level n,
7 ceil(level/4) x,
8 decode(mod(level,4),0,4,mod(level,4)) y
9 from dual
10 connect by level <= 4*4),
11 r(len,str,x,y) as (select 1,color,1,1
12 from t
13 union all
14 select r.len + 1,
15 r.str||t.color,
16 s.x,
17 s.y
18 from r,t,s
19 where r.len < 4*4
20 and r.len + 1 = s.n
21 and t.color not in (select substr(r.str,s2.n,1) node
22 from s s2
23 -- where abs(s.x - s2.x) + abs(s.y - s2.y) = 1
24 where ((s.x - s2.x = 1 and s2.y = s.y ) or (s.y - s2.y = 1 and s.x = s2.x))
25 and s2.n < r.len + 1
26 )
27 and substr(r.str,1,1) = 'B'
28 )
29 select count(str)*3
30 from r
31 where len = 4*4
32 and instr(r.str,'R') > 0
33 and instr(r.str,'Y') > 0
34 and instr(r.str,'B') > 0
35 /
COUNT(STR)*3
------------
7806
|
|