|
改用2进制表示已经经过的点,where条件写了就取不出值,放在/** **/位置就会数字溢出
/*and bitand(pe,se)=0*/
with t as(
select 1 p,power(2,1)e, 1 l, 2 r, 1 m from dual union
select 2 ,power(2,2) , 2 , 1 , 1 from dual union
select 3 ,power(2,3) , 1 , 3 , 2 from dual union
select 4 ,power(2,4) , 2 , 2 , 2 from dual union
select 5 ,power(2,5) , 3 , 1 , 2 from dual union
select 6 ,power(2,6) , 1 ,null, 3 from dual union
select 7 ,power(2,7) , 2 , 3 , 3 from dual union
select 8 ,power(2,8) , 3 , 2 , 3 from dual union
select 9 ,power(2,9) ,null, 1 , 3 from dual),
ex as(
select 1 a,6 b, 3 x from dual union
select 1 a,8 b, 4 x from dual union
select 2 a,7 b, 4 x from dual union
select 2 a,9 b, 5 x from dual union
select 3 a,5 b, 4 x from dual union
select 6 a,8 b, 7 x from dual union
select 6 a,9 b, 7 x from dual union
select 6 a,9 b, 8 x from dual union
select 7 a,9 b, 8 x from dual),
x as(select a,b,sum(power(2,x))se from ex group by a,b), --se中间包含的点的2进制和
p(lv,path,l1,r1,m1,pe)as
(
select 1,p,l,r,m,e from t
union all
select lv+1,path*10+p,l,r,m,pe+e+nvl(se,0) from p inner join t on(
lv<6 and bitand(e,pe)=0 and
(l1=l or r1=r or m1=m)
and (
(instr(path,p)=0 and lv<5)
or
(instr(path,p)=1 and lv=5)
))
left join x on(substr(path,-1)||p in (a*10+b,b*10+a) /** **/)
----where bitand(pe,se)=0
)
select min(path) from p where lv=6
group by pe-power(2,substr(path,-1))
; |
|