LintCode:背包问题 II
来源:互联网 发布:金融行业 数据安全 编辑:程序博客网 时间:2024/05/16 06:00
LintCode:背包问题 II
class Solution: # @param m: An integer m denotes the size of a backpack # @param A & V: Given n items with size A[i] and value V[i] # @return: The maximum value def backPackII(self, m, A, V): # write your code here a = m b = len(A) A.insert(0, 0) V.insert(0, 0) ans = [[0 for i in range(a+1)] for j in range(b+1)] for i in range(1, b+1): for j in range(1, a+1): if j >= A[i]: ans[i][j] = max(ans[i-1][j-A[i]] + V[i], ans[i-1][j]) else: ans[i][j] = max(ans[i-1][j], ans[i][j-1]) return ans[b][a]
0 0
- LintCode-背包问题 II
- LintCode : 背包问题 II
- LintCode : 背包问题 II
- LintCode:背包问题 II
- lintcode--背包问题II
- lintcode-背包问题II-125
- LintCode:M-背包问题 II
- LintCode刷题--背包问题 II
- LintCode 125. 背包问题 II
- 【LintCode】 Backpack II 背包问题II
- LintCode Backpack II(背包II)
- 【LintCode】Backpack 背包问题
- lintcode-背包问题-92
- LintCode :背包问题
- lintcode backpack 背包问题
- LintCode:背包问题
- LintCode(M)背包问题
- LintCode:背包问题
- map的嵌套使用
- Markdown简明语法
- uva12716 GCD等于XOR 筛法枚举
- QRgb 学习
- hdu2176 取(m堆)石子游戏(nim博弈)
- LintCode:背包问题 II
- 解决“Cannot merge new index 67208 into a non-jumbo instruction”的问题
- Java NIO原理图文分析及代码实现
- I/O流
- 科室软件开发流程规范
- poj2376Cleaning Shifts_贪心
- Android面试整理之UI部分——实现View的弹性滑动的三种方式(一)
- 基于GPUImage的实时美颜滤镜
- Linux的screenfetch和Linux_logo