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<=$n;$i++){
$weight=rand(1,20);
$price=rand(1,10);
$x[$i]=new tanxin($weight,$price);
}
//输出结果
function display($x)
{
$len=count($x);
foreach($x as $val){
echo $val->weight,' ',$val->price;
echo '
';
}
}
//按照价格和重量比排序
function tsort(&$x)
{
$len=count($x);
for($i=1;$i<=$len;$i++)
{
for($j=1;$j<&