-
Notifications
You must be signed in to change notification settings - Fork 23
/
Main.java
33 lines (25 loc) · 989 Bytes
/
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int count = scanner.nextInt();
List<Item> items = new LinkedList<Item>();
for (int i = 0; i < count; i++) {
Item item = new Item();
item.label = scanner.nextInt();
item.value = scanner.nextDouble();
item.weight = scanner.nextDouble();
items.add(item);
}
int capacity = scanner.nextInt();
List<KnapsackSolver> solvers = new ArrayList<KnapsackSolver>();
if (items.size() <= 20)
solvers.add(new BruteForceSolver(items, capacity));
solvers.add(new GreedySolver(items, capacity));
solvers.add(new DynamicProgrammingSolver(items, capacity));
solvers.add(new BranchAndBoundSolver(items, capacity));
for (KnapsackSolver solver : solvers) {
System.out.println(solver.solve());
}
}
}