-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKnapsackv3.java
80 lines (62 loc) · 2.07 KB
/
Knapsackv3.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Program2;
import java.util.Scanner;
/**
*
* @author Mayor Kucing
*/
public class Knapsackv3 {
private int n;
private int kapasitas;
private int[][] barang;
private int totalBenefit;
private double[] bobot;
private double[] nilai;
private double temp[][] = new double[n][n];
public Knapsackv3(int n, int kapasitas, double[] bobot, double[] nilai) {
this.n = n;
this.kapasitas = kapasitas;
this.bobot = bobot;
this.nilai = nilai;
this.barang = new int[n + 1][kapasitas + 1];
}
public int max(int a, int b) {
return a > b ? a : b;
}
public void solve() {
for (int i = 0; i < Math.pow(n, 2); i++) {
for (int j = 0; j < n; j++) {
for (int w = 0; w < 1; w++) {
temp[j][w] = max(barang[j][w], barang[j][w + 1]);
}
}
}
}
public static void main(String[] args) {
int kapasitas, n;
Scanner in = new Scanner(System.in);
System.out.print("Masukkan jumlah N : ");
n = in.nextInt();
double barang[][] = new double[n][n], bobot[] = new double[n], nilai[] = new double[n];
System.out.print("Masukkan Kapasitas Muatan : ");
kapasitas = in.nextInt();
System.out.println("Masukkan Bobot : ");
for (int i = 0; i < n; i++) {
barang[i][0] = in.nextInt();
bobot[i] = barang[i][0];
}
System.out.println("Masukkan Keuntungan : ");
for (int i = 0; i < n; i++) {
barang[i][1] = in.nextInt();
nilai[i] = barang[i][1];
}
for (int i = 0; i < n; i++) {
barang[i][2] = barang[i][0] / barang[i][1];
}
Knapsackv3 knp = new Knapsackv3(n, kapasitas, bobot, nilai);
}
}