Lintcode125 Backpack ||solution 题解
来源:互联网 发布:生化危机6mac 编辑:程序博客网 时间:2024/06/06 01:44
【题目描述】
Givennitems with size Aiand value Vi, and a backpack with sizem. What's the maximum value can you put into the backpack?
给出n个物品的体积A[i]和其价值V[i],将他们装入一个大小为m的背包,最多能装入的总价值有多大?
【注】:A[i], V[i], n, m均为整数。你不能将物品进行切分。你所挑选的物品总体积需要小于等于给定的m。
【题目链接】
www.lintcode.com/en/problem/backpack-ii/
【题目解析】
首先定义状态K(i,w)K(i,w)K(i,w) 为前 iii 个物品放入size为 www 的背包中所获得的最大价值,则相应的状态转移方程为:K(i,w)=max{K(i−1,w),K(i−1,w−wi)+vi}K(i,w) = \max {K(i-1, w), K(i-1, w - w_i) + v_i}K(i,w)=max{K(i−1,w),K(i−1,w−wi)+vi}
使用二维矩阵保存结果result,返回result矩阵的右下角元素——背包size限制为m时的最大价值。
【参考答案】
www.jiuzhang.com/solutions/backpack-ii/
阅读全文
0 0
- Lintcode125 Backpack ||solution 题解
- Lintcode92 Backpack solution 题解
- Backpack
- backpack
- backpack
- backpack
- Backpack
- Lintcode13 strStr solution 题解
- Lintcode15 Permutations solution 题解
- Lintcode17 Subsets solution 题解
- Lintcode109 Triangle solution 题解
- Lintcode111 ClimbingStairs solution 题解
- Lintcode129 Rehashing solution 题解
- Lintcode130 Heapify solution 题解
- Lintcode141 Sqrtx solution 题解
- Lintcode152 Combinations solution 题解
- [题解]NOIP2017 Day1 Solution
- [题解]NOIP2017 Day2 Solution
- express取参数req.query, req.params, req.body方法如何使用
- Tensorflow 学习笔记- tensor的声明
- OpenGL的第一天【VS2017+OpenGL环境的配置】
- ServletContextListener
- S5PV210中断系统
- Lintcode125 Backpack ||solution 题解
- poj 1459 Power Network
- Redux讲解
- JSONP是什么
- 2017 ACM-ICPC 亚洲区(乌鲁木齐赛区)网络赛 F island
- HDU 2594 Simpsons’ Hidden Talents 两字符串前缀与后缀的最长公共部分
- 《PID控制算法的C语言实现》学习笔记
- 哈哈日语 学渣的日语N1失败经验谈
- 更改 Tomcat 使用的 JDK 版本