Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,23 @@
|
|||
>function %maxsubs (v,n) ...
|
||||
$if n==1 then
|
||||
$ if (v[1]<0) then return {zeros(1,0),zeros(1,0)}
|
||||
$ else return {v,v};
|
||||
$ endif;
|
||||
$endif;
|
||||
${v1,v2}=%maxsubs(v[1:n-1],n-1);
|
||||
$m1=sum(v1); m2=sum(v2); m3=m2+v[n];
|
||||
$if m3>0 then v3=v2|v[n]; else v3=zeros(1,0); endif;
|
||||
$if m3>m1 then return {v2|v[n],v3};
|
||||
$else return {v1,v3};
|
||||
$endif;
|
||||
$endfunction
|
||||
>function maxsubs (v) ...
|
||||
${v1,v2}=%maxsubs(v,cols(v));
|
||||
$return v1
|
||||
$endfunction
|
||||
>maxsubs([0, 1, 2, -3, 3, -1, 0, -4, 0, -1, -4])
|
||||
[ 0 1 2 ]
|
||||
>maxsubs([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])
|
||||
[ 3 5 6 -2 -1 4 ]
|
||||
>maxsubs([-1, -2, -3, -4, -5])
|
||||
Empty matrix of size 1x0
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
>function maxsubsbrute (v) ...
|
||||
$ n=cols(v);
|
||||
$ A=zeros(n*(n-1),n);
|
||||
$ k=1;
|
||||
$ for i=1 to n-1;
|
||||
$ for j=i to n;
|
||||
$ A[k,i:j]=1;
|
||||
$ k=k+1;
|
||||
$ end;
|
||||
$ end;
|
||||
$ k1=extrema((A.v')')[4];
|
||||
$ return v[nonzeros(A[k1])];
|
||||
$ endfunction
|
||||
>maxsubsbrute([0, 1, 2, -3, 3, -1, 0, -4, 0, -1, -4])
|
||||
[ 0 1 2 ]
|
||||
>maxsubsbrute([-1, -2, 3, 5, 6, -2, -1, 4, -4, 2, -1])
|
||||
[ 3 5 6 -2 -1 4 ]
|
||||
>maxsubsbrute([-1, -2, -3, -4, -5])
|
||||
Empty matrix of size 1x0
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
>function test ...
|
||||
$ loop 1 to 10000000
|
||||
$ v=intrandom(1,intrandom(6)+6,20)-10;
|
||||
$ if sum(maxsubs(v))!=sum(maxsubsbrute(v)) then
|
||||
$ v, error("Found a wrong test example");
|
||||
$ endif;
|
||||
$ endfunction
|
||||
>test
|
||||
Loading…
Add table
Add a link
Reference in a new issue