|
#11
--不扣分的有效着色方案有多少种,理论上,找不到方案,N-1就是X的最大值
--N = 3, 24
4, 450
5, 17136
6, ...
(下面的SQL很蠢,先小试一下,S应该先修枝)
with t as (select level n from dual connect by level <=5),
triangle as (select t1.n x,t2.n y,t3.n z
from t t1,t t2,t t3
where t1.n < t2.n
and t2.n < t3.n),
triangle_3e as (select x,y,z, x a1,y b1,x a2,z b2,y a3,z b3 from triangle),
all_edges as (select rownum rn,a,b
from ( select distinct a,b
from (
select a1 a,b1 b from triangle_3e
union all
select a2,b2 from triangle_3e
union all
select a3,b3 from triangle_3e
)
order by a,b
)
),
c as (select 'R' color from dual
union all
select 'Y' from dual
union all
select 'B' from dual),
s(lvl,color_list) as (select 1, color
from c
where color = 'R'
union all
select s.lvl + 1,
s.color_list||c.color
from s,c
where s.lvl < (select count(rn) from all_edges)
)
select 3*count(*)
from (
select v.color_list
from (
select x,y,z,
(select rn from all_edges where a=a1 and b=b1) e1,
(select rn from all_edges where a=a2 and b=b2) e2,
(select rn from all_edges where a=a3 and b=b3) e3
from triangle_3e
) u,
( select color_list
from s
where lvl = (select count(rn) from all_edges)
) v
where substr(v.color_list,e1,1)
||substr(v.color_list,e2,1)
||substr(v.color_list,e3,1) not in ('BBB','RRR','YYY')
group by v.color_list
having count(*) = (select count(*) from triangle_3e)
)
|
|