Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
# dynamic programming:
|
||||
LIS := proc(L)
|
||||
local i, j;
|
||||
local index := 1;
|
||||
local output := Array(1..numelems(L), i -> Array(1..0));
|
||||
|
||||
for i from 1 to numelems(L) do
|
||||
for j from 1 to i - 1 do
|
||||
if (L[j] < L[i]) and (upperbound(output[j]) > upperbound(output[i])) then
|
||||
output[i] := copy(output[j]);
|
||||
end if;
|
||||
end do;
|
||||
# append current value
|
||||
output[i] ,= L[i];
|
||||
end do;
|
||||
|
||||
#output longest subsequence using loop
|
||||
for i from 2 to numelems(L) do
|
||||
if (upperbound(output[i]) > upperbound(output[index])) then
|
||||
index := i;
|
||||
end if;
|
||||
end do;
|
||||
|
||||
return output[index];
|
||||
|
||||
end proc:
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
i := max[index](map(numelems,output));
|
||||
output[i];
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
L := [3, 2, 6, 4, 5, 1];
|
||||
M := [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15];
|
||||
LIS(L);
|
||||
LIS(M);
|
||||
Loading…
Add table
Add a link
Reference in a new issue