Created
February 15, 2020 13:50
-
-
Save JohnItoo/37c929a7700ae46ff57abc65129b5551 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 decideThree() { | |
int slizes = slices.size(); | |
List<Integer>[] adjList = new List[slizes]; | |
for (int i = 0; i < slizes; ++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)]) { | |
int count = freqMap.get(slices.get(j)); | |
if (count <= 0) continue; | |
adjList[j].add(i); | |
freqMap.put(slices.get(j), count - 1); | |
done[i] = true; | |
break; | |
} | |
} | |
} | |
int maxAtt = 0; | |
//look for everywhere in adjList that has that maxValue? | |
//adjlist here is a list of all values that this slice can make | |
for (int i = maxPizzas; i >= 0; --i) { | |
if (done[i]) { | |
maxAtt = i; | |
break; | |
} | |
} | |
for(int i = 0; i<slizes; ++i) { | |
List<Integer> currList = adjList[i]; | |
for(int el : currList) { | |
if(el == maxAtt) { | |
solution.add(i); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment