mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-12-19 07:00:35 +08:00
style: enabled InnerAssignment in checkstyle (#5162)
* style: enabled InnerAssignment in checkstyle * Refactor code formatting in KnapsackMemoization.java and UnionFind.java * style: remove redundant blank line * style: mark `includeCurrentItem` and `excludeCurrentItem` as `final` * style: remove `KnapsackMemoization` from `pmd-exclude.properties` * style: use `final` --------- Co-authored-by: Piotr Idzik <65706193+vil02@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f8e62fbb90
commit
0f42e995a4
@@ -40,8 +40,15 @@ public class KnapsackMemoization {
|
||||
dpTable[numOfItems][capacity] = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
|
||||
return dpTable[numOfItems][capacity];
|
||||
} else {
|
||||
// Return value of table after storing
|
||||
return dpTable[numOfItems][capacity] = Math.max((profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable)), solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable));
|
||||
// case 1. include the item, if it is less than the capacity
|
||||
final int includeCurrentItem = profits[numOfItems - 1] + solveKnapsackRecursive(capacity - weights[numOfItems - 1], weights, profits, numOfItems - 1, dpTable);
|
||||
|
||||
// case 2. exclude the item if it is more than the capacity
|
||||
final int excludeCurrentItem = solveKnapsackRecursive(capacity, weights, profits, numOfItems - 1, dpTable);
|
||||
|
||||
// Store the value of function call stack in table and return
|
||||
dpTable[numOfItems][capacity] = Math.max(includeCurrentItem, excludeCurrentItem);
|
||||
return dpTable[numOfItems][capacity];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user