Created
February 15, 2020 08:54
-
-
Save JohnItoo/3ac1d3c9f6189946fc08684e82f95145 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void decideTwo() { | |
List<Integer>[] adjList = new List[maxPizzas + 1]; | |
for (int i = 0; i <= maxPizzas; ++i) { | |
adjList[i] = new ArrayList<>(); | |
} | |
boolean[] done = new boolean[maxPizzas + 1]; | |
done[0] = true; | |
for (int i = 1; i <= maxPizzas; ++i) { | |
for (int j = 0; j < slices.size(); ++j) { | |
if (i - slices.get(j) < 0) continue; | |
if (done[i - slices.get(j)]) { | |
List<Integer> curr = adjList[i - slices.get(j)]; | |
boolean isUsed = false; | |
for (Integer integer : curr) { | |
if (integer == j) { | |
isUsed = true; | |
break; | |
} | |
} | |
if (!isUsed) { | |
for (int st : curr) { | |
adjList[i].add(st); | |
} | |
adjList[i].add(j); | |
done[i] = true; | |
break; | |
} | |
} | |
} | |
} | |
for (int i = maxPizzas; i >= 0; --i) { | |
if (done[i]) { | |
solution = adjList[i]; | |
System.out.println(i); | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment