| 33 | } |
| 34 | |
| 35 | public static void main(String[] args) |
| 36 | { |
| 37 | int i, n, W; |
| 38 | Scanner sc = new Scanner(System.in); |
| 39 | System.out.println("Enter the number of items : "); |
| 40 | n = sc.nextInt(); |
| 41 | System.out.println("Enter the maximum weight/capacity : "); |
| 42 | W = sc.nextInt(); |
| 43 | int wt[] = new int[n]; |
| 44 | int val[] = new int[n]; |
| 45 | System.out.println("Enter the weights of the items : "); |
| 46 | for(i=0; i<n; i++) |
| 47 | { |
| 48 | wt[i] = sc.nextInt(); |
| 49 | } |
| 50 | System.out.println("Enter their corresponding values : "); |
| 51 | for(i=0; i<n; i++) |
| 52 | { |
| 53 | val[i] = sc.nextInt(); |
| 54 | } |
| 55 | KnapSack ob = new KnapSack(); |
| 56 | int res = ob.knapSack(W, wt, val, n); |
| 57 | System.out.println("Total profit : "+res); |
| 58 | } |
| 59 | } |