Skip to content

Instantly share code, notes, and snippets.

@JohnItoo
Created February 15, 2020 13:50
Show Gist options
  • Save JohnItoo/37c929a7700ae46ff57abc65129b5551 to your computer and use it in GitHub Desktop.
Save JohnItoo/37c929a7700ae46ff57abc65129b5551 to your computer and use it in GitHub Desktop.
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