|
|
本帖最后由 〇〇 于 2021-10-9 15:01 编辑
8 8 5
with RECURSIVE
t(n,c,x,y) as (select level,chr(32+level),ceil(level/8),mod(level-1,8)+1 from generate_series(1,8*8)level),
s(lvl,n,
--nlist,
clist,rn) as (select 1::int,
n,
--cast(n as varchar2(100)),
c,1::bigint
from t where t.n between 1 and 4
union all
select lvl + 1,
b.n,
--nlist||','||b.n,
clist||','||b.c ,row_number()over(order by random())
from s,t b
where s.n < b.n and b.n between lvl/5*8+1 and lvl/5*8+8 and rn<1200
and (select greatest(sum(case when a.x = b.x then 1 end),
sum(case when a.y = b.y then 1 end),
sum(case when a.x-b.x = a.y-b.y then 1 end),
sum(case when a.x-b.x = b.y-a.y then 1 end)
)
from t a
where position(a.c in clist||','||b.c)>0)<=5
)
select max(lvl),count(case when lvl=40 then 1 end) from s;
max | count
-----+-------
40 | 1
(1 行记录)
时间:2483.671 ms (00:02.484)
8 8 6with RECURSIVE
t(n,c,x,y) as (select level,chr(32+level),ceil(level/8),mod(level-1,8)+1 from generate_series(1,8*8)level),
s(lvl,n,
--nlist,
clist,rn) as (select 1::int,
n,
--cast(n as varchar2(100)),
c,1::bigint
from t where t.n between 1 and 4
union all
select lvl + 1,
b.n,
--nlist||','||b.n,
clist||','||b.c ,row_number()over(order by random())
from s,t b
where s.n < b.n and b.n between lvl/6*8+1 and lvl/6*8+8 and rn<3000
and (select greatest(sum(case when a.x = b.x then 1 end),
sum(case when a.y = b.y then 1 end),
sum(case when a.x-b.x = a.y-b.y then 1 end),
sum(case when a.x-b.x = b.y-a.y then 1 end)
)
from t a
where position(a.c in clist||','||b.c)>0)<=6
)
select max(lvl),count(case when lvl=48 then 1 end) from s;
max | count
-----+-------
48 | 1
(1 行记录)
时间:6429.706 ms (00:06.430)
--8 8 7
with RECURSIVE
t(n,c,x,y) as (select level,chr(32+level),ceil(level/8),mod(level-1,8)+1 from generate_series(1,8*8)level),
s(lvl,n,
--nlist,
clist,rn) as (select 1::int,
n,
--cast(n as varchar2(100)),
c,1::bigint
from t where t.n between 1 and 4
union all
select lvl + 1,
b.n,
--nlist||','||b.n,
clist||','||b.c ,row_number()over(order by random())
from s,t b
where s.n < b.n and b.n between lvl/7*8+1 and lvl/7*8+8 and rn<3000
and (select greatest(sum(case when a.x = b.x then 1 end),
sum(case when a.y = b.y then 1 end),
sum(case when a.x-b.x = a.y-b.y then 1 end),
sum(case when a.x-b.x = b.y-a.y then 1 end)
)
from t a
where position(a.c in clist||','||b.c)>0)<=7
)
select max(lvl),count(case when lvl=56 then 1 end) from s;
max | count
-----+-------
56 | 1
(1 行记录)
时间:5250.644 ms (00:05.251)
insert into t884
with RECURSIVE
t(n,c,x,y) as (select level,chr(32+level),ceil(level/9),mod(level-1,9)+1 from generate_series(1,9*9)level),
s(lvl,n,
--nlist,
clist,rn) as (select 1::int,
n,
--cast(n as varchar2(100)),
c,1::bigint
from t where t.n between 1 and 4
union all
select lvl + 1,
b.n,
--nlist||','||b.n,
clist||','||b.c ,row_number()over(order by random())
from s,t b
where s.n < b.n and b.n between lvl/7*9+1 and lvl/7*9+9 and rn<10000
and (select greatest(sum(case when a.x = b.x then 1 end),
sum(case when a.y = b.y then 1 end),
sum(case when a.x-b.x = a.y-b.y then 1 end),
sum(case when a.x-b.x = b.y-a.y then 1 end)
)
from t a
where position(a.c in clist||','||b.c)>0)<=7
)
select * from s where lvl=63;
INSERT 0 9
时间:38117.848 ms (00:38.118)
test=# select * from t884 where lvl=63;
lvl | n | clist | rn
-----+----+-------------------------------------------------------------------------------------------------------------------------------+----
63 | 81 | ",#,$,%,&,',(,*,,,-,.,/,0,1,3,4,5,7,9,:,;,<,?,@,A,B,C,D,E,F,G,H,J,L,M,N,O,P,Q,S,T,V,W,X,Z,[,],^,_,`,a,b,d,e,f,h,j,k,l,m,n,p,q | 1
...
(9 行记录)
时间:0.668 ms
能否数学上证明n*n 每行最多m的解就是n*m?
|
|