背包问题的haskell解法
来源:互联网 发布:java 爬虫 编辑:程序博客网 时间:2024/06/10 07:25
-- file: knapsack1.hs
maxVal [] [] _ = 0
maxVal (w:ws) (v:vs) aW =
if w > aW
then
without_it
else
max without_it (with_it+v)
where
without_it = maxVal ws vs aW
with_it = maxVal ws vs (aW-w)
weights = [1, 5, 3, 4]
vals = [15, 10, 9, 5]
evalue = maxVal weights vals 8
-- file: knapsack2.hs
maxVal [] [] _ = (0, 0)
maxVal (w:ws) (v:vs) aW =
if w > aW
then
(without_it, nc1+1)
else
(max without_it (with_it+v), nc1+nc2+1)
where
(without_it, nc1) = maxVal ws vs aW
(with_it, nc2) = maxVal ws vs (aW-w)
weights = [1, 5, 3, 4]
vals = [15, 10, 9, 5]
evalue = maxVal weights vals 8
-- file: knapsack3.hs
maxVal [] [] _ = (0, 0, [])
maxVal (w:ws) (v:vs) aW =
if w > aW then
(without_it, nc1+1, 0:xs1)
else if without_it > with_it then
(without_it, nc1+nc2+1, 0:xs1)
else
(with_it, nc1+nc2+1, 1:xs2)
where
(without_it, nc1, xs1) = maxVal ws vs aW
(with_it', nc2, xs2) = maxVal ws vs (aW-w)
with_it = with_it' + v
weights = [1, 5, 3, 4]
vals = [15, 10, 9, 5]
evalue = maxVal weights vals 8
- 背包问题的haskell解法
- 背包分组问题的解法
- 背包问题的解法源代码
- 一种背包问题的解法
- 背包问题的递归解法
- 背包问题的遗传算法解法
- 背包问题的非递归解法
- P11: 背包问题的搜索解法
- 01 背包问题的另类解法
- 0-1背包问题的各种解法
- P11: 背包问题的搜索解法
- 01背包问题的优化解法
- 0-1背包问题的一种解法
- 背包问题的多个解法
- 背包问题的动态规划解法
- 背包问题的几种解法总结
- 01背包问题的三种解法
- 01背包问题的动态规划解法
- Orace及SqlServer的多表关联更新
- 目录.C/C++基础
- 保障消费者知情权是食品安全管理的重心
- c语言反汇编公式
- 可怜
- 背包问题的haskell解法
- OpenDNS、DNS解析、13个根域名服务器、根域名镜像服务器
- 版本源代码管理和变更管理联合使用
- 关于GStreamer的一个牛X网页(字符叠加,画中画,屏墙)
- gstreamer开发
- 使用 GStreamer 进行多用途的多媒体处理
- 广度优先搜索(临界表实现)
- android学习
- 装配站问题(动态规划)