Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 28 May Minimum cost to fill given weight in a bag
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Solution {
public:
int minimumCost(int n, int w, vector<int> &cost) {
vector<int> dp(w + 1, INT_MAX);
dp[0] = 0;

for (int i = 0; i < n; i++)
for (int j = i + 1; j <= w; j++)
dp[j] = min(dp[j], cost[i] + dp[j - i - 1]);

return dp[w];
}
};