woonie

solve

Mar 24th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.64 KB | None | 0 0
  1.  20     public int solve(LinkedList<Integer> myBag, int remWeight) {
  2.  21         // implementation
  3.  22         int output;
  4.  23         int topWeight, nextRemWeight;
  5.  24         if (myBag.isEmpty() || remWeight == 0){
  6.  25             output = 1;
  7.  26         } else{
  8.  27             topWeight = myBag.pop();
  9.  28             if (topWeight > remWeight){
  10.  29                 output = solve(myBag, remWeight);
  11.  30             } else {
  12.  31                 nextRemWeight = remWeight - topWeight;
  13.  32                 output = solve(myBag, remWeight) + solve(myBag, nextRemWeight);
  14.  33             }
  15.  34         }
  16.  35         return output;
  17.  36     }
Advertisement
Add Comment
Please, Sign In to add comment