背包以最小的成本

编程入门 行业动态 更新时间:2024-10-23 17:32:38
本文介绍了背包以最小的成本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有几种类型的硬币,每个人都有重量(WI)和成本(CI)。所以,我不得不做出一个背包与体重= W和它硬币(!)的最低成本。我不能老是让递推关系使用DP。

I've got several types of coins, each have weight (wi) and cost (ci). So I've got to make a knapsack with weight==W and (!) minimum cost of coins in it. I can`t make recurrence relation to use DP.

推荐答案

刚刚制定通常递推关系......

Just formulate the usual recurrence relation...

指定最小成本达到的总权重k作为Min_cost(k)的

Designate the minimum cost achievable with total weight k as Min_cost(k).

自引导与记忆化:

Min_cost(0) = cost of empty set = 0

然后解决增加使用的k值:

Then solve for increasing values of k using:

Min_cost(i+1) = min [Min_cost(i) + min [ci, for all items with wi = 1], Min_cost(i-1) + min [ci, for all items with wi = 2], Min_cost(i-2) + min [ci, for all items with wi = 3], ... Min_cost(2) + min [ci, for all items with wi = w-1], Min_cost(1) + min [ci, for all items with wi = w], Min_cost(0) + min [ci, for all items with wi = w+1]]

更多推荐

背包以最小的成本

本文发布于:2023-11-30 02:34:16,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648424.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:背包   最小   成本

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!