diff --git a/28 May Minimum cost to fill given weight in a bag b/28 May Minimum cost to fill given weight in a bag new file mode 100644 index 00000000..ec1ecfa3 --- /dev/null +++ b/28 May Minimum cost to fill given weight in a bag @@ -0,0 +1,13 @@ +class Solution { +public: + int minimumCost(int n, int w, vector &cost) { + vector 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]; + } +};