|
本帖最后由 〇〇 于 2018-11-22 14:30 编辑
去掉n>nx条件有很多重复,4个线段能算,12个就不行了
SQL> with point (n,a,b) as(
2 select level,ceil(level/2),mod(level-1,2)+1 from dual connect by level<=4),
3 line (n,n1,n2) as(select rownum,p1.n,p2.n from point p1,point p2 where abs(p2.a-p1.a) + abs(p2.b-p1.b)=1 and p1.n<p2.n),
4 shap (lv,nn,s,s2,nx) as(select 1,n,power(2,n),power(2,n1)+power(2,n2),n from line --s1 exists lines,s2 exists points
5 union all
6 select lv+1,n,s+power(2,n),
7 s2+power(2,n1)+power(2,n2)-bitand(s2, power(2,n1)+power(2,n2)), --BITOR(x,y) = (x + y) - BITAND(x, y)
8 greatest(nx,n)
9 from shap,line where -- n>nx and
10 bitand(s,power(2,n))=0 and (bitand(power(2,n1),s2)=power(2,n1) or bitand(power(2,n2),s2)=power(2,n2) ) and
11 lv<(select count(*) from line))
12 select count(unique s) from shap;
COUNT(UNIQUES)
--------------
13
SQL> set timi on
SQL> with point (n,a,b) as(
2 select level,ceil(level/3),mod(level-1,3)+1 from dual connect by level<=9),
3 line (n,n1,n2) as(select rownum,p1.n,p2.n from point p1,point p2 where abs(p2.a-p1.a) + abs(p2.b-p1.b)=1 and p1.n<p2.n),
4 shap (lv,nn,s,s2,nx) as(select 1,n,power(2,n),power(2,n1)+power(2,n2),n from line --s1 exists lines,s2 exists points
5 union all
6 select lv+1,n,s+power(2,n),
7 s2+power(2,n1)+power(2,n2)-bitand(s2, power(2,n1)+power(2,n2)), --BITOR(x,y) = (x + y) - BITAND(x, y)
8 greatest(nx,n)
9 from shap,line where -- n>nx and
10 bitand(s,power(2,n))=0 and (bitand(power(2,n1),s2)=power(2,n1) or bitand(power(2,n2),s2)=power(2,n2) ) and
11 lv<(select count(*) from line))
12 select count(unique s) from shap;
^Cwith point (n,a,b) as(
*
ERROR at line 1:
ORA-01013: user requested cancel of current operation
Elapsed: 00:00:41.89
|
|