tinycodinglm / math /math-0157.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame
1.35 kB
{"type": "session", "harness": "opencode", "id": "math-0157", "name": "Dynamic Programming Mathematical Foundations"}
{"type": "message", "message": {"role": "system", "content": "You are an expert mathematician and programmer."}}
{"type": "message", "message": {"role": "user", "content": "Explain DP math foundations"}}
{"type": "message", "message": {"role": "assistant", "content": "Optimal substructure: optimal solution contains optimal solutions to subproblems.\nOverlapping subproblems: same subproblems solved repeatedly, memoize.\n\nKnapsack: dp[i][w] = max value using items 1..i with capacity w. O(nW). Space optimize to O(W).\ndp[j] = max(dp[j], dp[j-w_i]+v_i) iterating j backward (0-1) or forward (unbounded).\n\nLongest common subsequence: dp[i][j] = dp[i-1][j-1]+1 if s[i]==t[j], else max(dp[i-1][j],dp[i][j-1]).\nEdit distance: dp[i][j] = min operations to transform s[1..i] to t[1..j]. Insert/delete/replace.\n\nPartition problems: dp[sum] = true if subset sums to total/2.\nBitmask DP: dp[mask] for subset {0..n-1} represented by bitmask. TSP: O(n*2^n).\n\nMatrix chain multiplication: dp[i][j] = min cost to multiply matrices i..j. O(n^3).\nOptimal BST: dp[i][j] = min cost tree for keys i..j with probabilities.\n\nInterval DP: dp[i][j] = best for range [i,j]. Merge: dp[i][j] = min(dp[i][k]+dp[k+1][j]) for split k."}}