DAA4
DAA4
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;
class Item {
float weight;
int value;
class Node {
int level, profit, bound;
float weight;
if (j < n)
profitBound += (int) ((W - totalWeight) * arr[j].value / arr[j].weight);
return profitBound;
}
int maxProfit = 0;
while (!priorityQueue.isEmpty()) {
u = priorityQueue.poll();
if (u.level == -1)
v = new Node(0, 0, 0);
else if (u.level == n - 1)
continue;
else
v = new Node(u.level + 1, u.profit, u.weight);
v.weight += arr[v.level].weight;
v.profit += arr[v.level].value;
return maxProfit;
}
scanner.close();
}
}
Output :