01背包问题 (python版)
来源:互联网 发布:华为面试 知乎 编辑:程序博客网 时间:2024/06/04 23:18
首先是问题描述:给定n种物品和一背包,物品i的重量是wi,其价值是pi,背包的容量是M,问如何选择装入背包中的物品总价值最大?
不用刚好装满
#!/usr/bin/pythonm = int(raw_input("get m as the max bag size:"))n = int(raw_input("get n as the goods tots:"))print("bag max store: %d, goods tots: %d" % (m, n))table = [ [0 for col in range(m+1)] for row in range(n+1)]p = [0]w = [0]for i in range(1, n+1): weigth = int(raw_input("get weigth:")) value = int(raw_input("get val:")) w.append(weigth) p.append(value)print pprint w#print tablefor row in range(1, n+1): for col in range(1, m+1): if(w[row] <= col and table[row - 1][col - w[row]] + p[row] > table[row - 1][col]): table[row][col] = table[row - 1][col - w[row]] + p[row] else: table[row][col] = table[row - 1][col]print "max value can store:" + str(table[n][m])
- 01背包问题 (python版)
- 01背包问题python实现
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包(01背包、完全背包、多重背包)问题总结
- 背包问题(01背包,完全背包,多重背包)
- 背包问题(01背包 + 完全背包 + 多重背包)
- 背包问题(01背包,完全背包,多重背包)
- 背包问题模板(01背包,完全背包,多重背包)
- 经典背包问题----(01背包、完全背包、多重背包)
- LintCode-背包问题(01背包问题)
- 01背包问题(动态规划)python实现
- 01背包问题(回溯法)python实现
- python 版 动态规划 背包问题算法
- 背包问题(c/python)
- 背包问题1(01背包)
- 超大背包问题(01背包)
- FZOJ1627 背包问题(01背包)
- 网络字节序和主机字节序
- Spring3整合Hibernate4 Lorg/hibernate/cache/CacheProvider异常
- 【随笔】排序二叉树的删除问题
- 线程私有数据
- 深入Oracle Log Buffer 发展史
- 01背包问题 (python版)
- C语言assert()函数用法总结
- SSIS_数据库表数据导出为XML格式
- [Error] g++.exe: 5\mingw\include: No such file or directory
- linux下生成.so文件和.a文件
- 手机APP与原生APP设计的区别
- 数据结构——几种链表基本操作
- ZOJ3587 Marlon's String
- TIME_WAIT状态