Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,11 @@
|
|||
table(+,+,max)
|
||||
lis_mode(In, Out,OutLen) =>
|
||||
one_is(In, [], Is),
|
||||
Out = reverse(Is),
|
||||
OutLen = Out.length.
|
||||
|
||||
one_is([], Current, Current2) => Current = Current2.
|
||||
one_is([H|T], Current, Final) =>
|
||||
( Current = [], one_is(T, [H], Final));
|
||||
( Current = [H1|_], H1 @< H, one_is(T, [H|Current], Final));
|
||||
one_is(T, Current, Final).
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
lis_cp(S, Res,Z) =>
|
||||
Len = S.len,
|
||||
X = new_list(Len),
|
||||
X :: 0..1,
|
||||
|
||||
increasing_except_0($[X[I]*S[I] : I in 1..Len]),
|
||||
Z #= sum(X),
|
||||
|
||||
solve($[max(Z)],X),
|
||||
% Extract the found LIS
|
||||
Res = [S[I] : I in 1..Len, X[I] == 1].
|
||||
|
||||
%
|
||||
% Ensures that array A is (strictly) increasing if we disregard any 0's
|
||||
%
|
||||
increasing_except_0(A) =>
|
||||
N = A.len,
|
||||
foreach(I in 1..N, J in I+1..N)
|
||||
(A[I] #!= 0 #/\ A[J] #!= 0) #=> (A[I] #< A[J])
|
||||
end.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
import sat. % for lis_cp
|
||||
% import cp. % Slower than sat on larger instances.
|
||||
|
||||
go =>
|
||||
nolog,
|
||||
Tests = [
|
||||
[3,2,6,4,5,1],
|
||||
[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],
|
||||
[1,1,1,1],
|
||||
[4,65,2,-31,0,99,83,782,1]
|
||||
],
|
||||
Funs = [lis_mode, lis_cp],
|
||||
|
||||
foreach(Fun in Funs)
|
||||
println(fun=Fun),
|
||||
foreach(Test in Tests)
|
||||
call(Fun,Test,Lis,Len),
|
||||
printf("%w: LIS=%w (len=%d)\n",Test, Lis,Len)
|
||||
end,
|
||||
nl,
|
||||
end,
|
||||
nl.
|
||||
Loading…
Add table
Add a link
Reference in a new issue