Knapsack
LeetCode 2218: Maximum Value of K Coins From Piles
·2 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
Prefix-Sum
Array
LeetCode 2218 note: piles are taken from the top, so taking x coins is worth a prefix sum; a grouped knapsack with dp[j] = the best value taking j coins so far, enumerating how many from each pile
Knapsack DP
·3 mins
Algorithm
Dynamic-Programming
Knapsack
Subset-Sum
0/1, unbounded, reachability, counting, and optimization states
LeetCode 4041: Minimum Operations to Form Subset Sum II
·2 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
Breadth-First-Search
Array
LeetCode 4041 note: with operations in any order, BFS finds every value a number can become (up to sum) with the fewest steps, then the same grouped 0/1 knapsack as 4040
LeetCode 4040: Minimum Operations to Form Subset Sum I
·2 mins
LeetCode
Medium
Dynamic-Programming
Knapsack
Array
LeetCode 4040 note: with multiplications before divisions, the best is always multiply-only or divide-only; list each number’s reachable values and costs, then run a grouped 0/1 knapsack
LeetCode 2585: Number of Ways to Earn Points
·2 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
Array
LeetCode 2585 note: a bounded (grouped) knapsack; each question type takes 0 to count questions, with capacity running backwards and the count enumerated inside
LeetCode 494: Target Sum
·3 mins
LeetCode
Medium
Dynamic-Programming
Knapsack
Subset-Sum
LeetCode note for Target Sum, rebuilt from the original learning note
LeetCode 416: Partition Equal Subset Sum
·3 mins
LeetCode
Medium
Dynamic-Programming
Knapsack
Subset-Sum
LeetCode note for Partition Equal Subset Sum, rebuilt from the original learning note
LeetCode 879: Profitable Schemes
·3 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
LeetCode note for Profitable Schemes, rebuilt from the original learning note
LeetCode 474: Ones and Zeroes
·3 mins
LeetCode
Medium
Dynamic-Programming
Knapsack
LeetCode note for Ones and Zeroes, rebuilt from the original learning note
LeetCode 1449: Form Largest Integer With Digits That Add Up To Target
·3 mins
LeetCode
Hard
Dynamic-Programming
Knapsack
LeetCode note for Form Largest Integer With Digits That Add Up To Target, rebuilt from the original learning note
LeetCode 1049: Last Stone Weight II
·3 mins
LeetCode
Medium
Dynamic-Programming
Knapsack
Subset-Sum
LeetCode note for Last Stone Weight II, rebuilt from the original learning note