Home  >  Article  >  php教程  >  PHP贪婪算法解决0-1背包问题实例分析

PHP贪婪算法解决0-1背包问题实例分析

WBOY
WBOYOriginal
2016-06-06 20:06:071602browse

这篇文章主要介绍了PHP贪婪算法解决0-1背包问题,实例分析了贪婪算法的原理与背包问题的实现技巧,需要的朋友可以参考下



本文实例讲述了PHP贪婪算法解决0-1背包问题的方法。分享给大家供大家参考。具体分析如下:

贪心算法解决0-1背包问题,全局最优解通过局部最优解来获得!比动态规划解决背包问题更灵活!

//0-1背包贪心算法问题 class tanxin{  public $weight;  public $price;  public function __construct($weight=0,$price=0)  { $this->weight=$weight; $this->price=$price;  } } //生成数据 $n=10; for($i=1;$i

希望本文所述对大家的php程序设计有所帮助。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn