ocaml: phase 5.1 stock_two.ml baseline (best of 2 transactions = 6)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Two-pass partition DP for max profit with at most 2 transactions:
left[i] = max single-trans profit in prices[0..i]
(forward scan tracking running min)
right[i] = max single-trans profit in prices[i..n-1]
(backward scan tracking running max)
answer = max over i of (left[i] + right[i])
For [3; 3; 5; 0; 0; 3; 1; 4]:
optimal partition i = 2:
left[2] = sell@5 after buy@3 = 2
right[2] = sell@4 after buy@0 in [2..7] = 4
total = 6
Tests parallel forward + backward passes on parallel DP arrays,
mixed ref + array state, for downto + for ascending scans on
the same data.
190 baseline programs total.
This commit is contained in:
@@ -407,6 +407,16 @@ _Newest first._
|
||||
binary search tree (`type 'a tree = Leaf | Node of 'a * 'a tree *
|
||||
'a tree`) with insert + in-order traversal. Tests parametric ADT,
|
||||
recursive match, List.append, List.fold_left.
|
||||
- 2026-05-11 Phase 5.1 — stock_two.ml baseline (max stock profit
|
||||
with at most 2 transactions on [3;3;5;0;0;3;1;4] = 6). Two-pass
|
||||
DP: left[i] = max single-transaction profit in prices[0..i]
|
||||
(forward, tracking running min), right[i] = max single-transaction
|
||||
profit in prices[i..n-1] (backward, tracking running max). Final
|
||||
answer = max over i of left[i]+right[i], partitioning at the
|
||||
best split. Optimal: buy@3, sell@5 (profit 2); buy@0, sell@4
|
||||
(profit 4); total = 6. Tests parallel forward + backward passes
|
||||
on parallel DP arrays, mixed ref+array state, downto + ascending
|
||||
scans on same data. 190 baseline programs total.
|
||||
- 2026-05-11 Phase 5.1 — house_robber.ml baseline (linear-DP
|
||||
max non-adjacent-sum on [2;7;9;3;1;5;8;6] = 22). dp[i] =
|
||||
max(dp[i-2]+houses[i], dp[i-1]). Optimal pick {7, 9, 5, 8} but
|
||||
|
||||
Reference in New Issue
Block a user