|
|
我的写法也是2826:
with
c as (select 0 c from dual union all select 1 from dual union all select 2 from dual union all select 4 from dual)
,t (lvl,colors,painted,str) as (
select 1,c,decode(c,0,0,1),cast(c as varchar2(10)) from c
union all
select t.lvl+1,t.colors+c.c-bitand(t.colors,c.c),t.painted + decode(c.c,0,0,1),t.str||c
from t,c
where t.lvl<9
and t.painted + decode(c.c,0,0,1)<=5
and (c.c>0 and (t.lvl not in (3,6) and substr(t.str,t.lvl,1)<>c --------- 相邻不能同色
or t.lvl in (3,6)
)
and (t.lvl not in (1,2) and substr(t.str,t.lvl-2,1)<>c
or t.lvl in (1,2)
)
and (t.lvl<8 ------- 最后一块如果上色,不能孤立
or t.lvl=8 and (substr(t.str,6,1)>'0' or substr(t.str,8,1)>'0')
)
or
-- 排除以前出现的孤立色块
c.c=0 and (t.lvl<3
or t.lvl=3 and not (substr(t.str,1,1)>0 and substr(t.str,2,1)=0)
or t.lvl=4 and not (substr(t.str,1,1)=0 and substr(t.str,2,1)>0 and substr(t.str,3,1)=0)
or t.lvl=5 and not (substr(t.str,2,1)=0 and substr(t.str,3,1)>0)
or t.lvl=6 and not (substr(t.str,1,1)=0 and substr(t.str,4,1)>0 and substr(t.str,5,1)=0)
or t.lvl=7 and not (substr(t.str,2,1)=0 and substr(t.str,4,1)=0 and substr(t.str,5,1)>0 and substr(t.str,6,1)>0)
and not (substr(t.str,4,1)=0 and substr(t.str,7,1)>0)
or t.lvl=8 and not (substr(t.str,3,1)=0 and substr(t.str,5,1)=0 and substr(t.str,6,1)>0)
and not (substr(t.str,5,1)=0 and substr(t.str,7,1)=0 and substr(t.str,8,1)>0)
)
)
)
select count(*) from t where colors=7 and painted=5 and lvl=9;
给加菲猫转个章。 |
|