|
照例, 先来的总是最笨的办法。
暴力求解:
with tstr as (
select 1 r, '75 ' str from dual union all
select 2 r, '95 64 ' str from dual union all
select 3 r, '17 47 82 ' str from dual union all
select 4 r, '18 35 87 10 ' str from dual union all
select 5 r, '20 04 82 47 65 ' str from dual union all
select 6 r, '19 01 23 75 03 34 ' str from dual union all
select 7 r, '88 02 77 73 07 63 67 ' str from dual union all
select 8 r, '99 65 04 28 06 16 70 92 ' str from dual union all
select 9 r, '41 41 26 56 83 40 80 70 33 ' str from dual union all
select 10 r, '41 48 72 33 47 32 37 16 94 29 ' str from dual union all
select 11 r, '53 71 44 65 25 43 91 52 97 51 14 ' str from dual union all
select 12 r, '70 11 33 28 77 73 17 78 39 68 17 57 ' str from dual union all
select 13 r, '91 71 52 38 17 14 91 43 58 50 27 29 48 ' str from dual union all
select 14 r, '63 66 04 68 89 53 67 30 73 16 69 87 40 31 ' str from dual union all
select 15 r, '04 62 98 27 23 09 70 98 73 93 38 53 60 04 23' str from dual )
,t1 as (select rownum c from dual connect by level<=15)
,t01 as (select rownum-1 n01 from dual connect by rownum<=2)
,t2 as (select r, c, to_number(substr(str, c*3-2, 2)) num from tstr, t1 where substr(str, c*3-2, 2) is not null)
--select sys_connect_by_path(num,'/') from t2 where level=15 start with r=1 and c=1 connect by r=prior r+1 and c in (prior c, prior c+1)
, tree(tr,tc,v, sm) as (
select 1, 1, num , num from t2 where r=1 and c=1
union all
select
tr+1,
tc+n01,
(select num from t2 where r= tr+1 and c = tc+n01),
sm + (select num from t2 where r= tr+1 and c = tc+n01)
from tree, t01 where tr<15)
select max(sm) from tree where tr=15 order by tr, tc
MAX(SM)
----------
1074
Executed in 1.828 seconds
那颗大树太占地方了, 后面再写语句都把那个大树略过, 只写tstr来引用。 |
|