staafl

Untitled

Jun 19th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. for (int i = 1; i < items.Length; i++) // * for each item (ex: beer, wiskey, vodka...)
  2. {
  3. for (int k = 1; k < capacity + 1; k++) // * for each capacity of the bag (ex: if max capacity = 5 -> 1,2,3,4,5 / adds 1)
  4. {
  5. if (items[i].Weight <= k) // * the weigth of the current item (items[i-1]) is le(less than or equal) to the current bag capacity
  6. {
  7. int remainingSpace = k - items[i].Weight; // * remaining space - the difference between the weigth of the currentItem and the current capacity of the bag.
  8.  
  9. int valueAbove = valuesArray[i - 1, k]; // * row above, same coll
  10.  
  11. if (remainingSpace >= 0)
  12. {
  13. int sumValue = items[i].Value + valuesArray[i - 1, remainingSpace]; //* currentItem.Value + value from above row, remainingSpace col.
  14.  
  15. if (valueAbove > sumValue) // * gets the biggest value
  16. {
  17. valuesArray[i, k] = valueAbove;
  18. keepArray[i, k] = 0;
  19. }
  20. else
  21. {
  22. valuesArray[i, k] = sumValue;
  23. keepArray[i, k] = 1;
  24. }
  25. }
  26. else
  27. {
  28. valuesArray[i, k] = valueAbove;
  29. keepArray[i, k] = 0;
  30. }
  31. }
  32. }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment