Guest User

Untitled

a guest
Aug 5th, 2015
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.48 KB | None | 0 0
  1. function tryKnapsack($w4, $v4, $maxTake, $i) {
  2.     echo $i;
  3.     if ($i % 2) {
  4.         $vOrw = $v4;
  5.     } else {
  6.         $vOrw = $w4;
  7.     }
  8.     $chosenWeight = 0;
  9.     $m = array();
  10.     $pItems = array();
  11.     list($totVal, $chosenItems) = knapSolveFast2($w4, $vOrw, floor(sizeof($w4)/2)-$i, $maxTake, $m, $pItems);
  12.    
  13.     foreach($chosenItems as $key) {
  14.         $chosenWeight += $w4[$key];
  15.     }
  16.    
  17.     if ($chosenWeight > 0 || $i > 10) {
  18.         return $chosenItems;
  19.     } else {
  20.         return tryKnapsack($w4, $v4, $maxTake, $i+1);
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment