Class Knapsack01DynamicOneSolution


  • public class Knapsack01DynamicOneSolution
    extends java.lang.Object
    Compilation: javac Knapsack.java Execution: java Knapsack N W Generates an instance of the 0/1 knapsack problem with N items and maximum weight W and solves it in time and space proportional to N * W using dynamic programming. For testing, the inputs are generated at random with weights between 0 and W, and profits between 0 and 1000. % java Knapsack 6 2000 item profit weight take 1 874 580 true 2 620 1616 false 3 345 1906 false 4 369 1942 false 5 360 50 true 6 470 294 true
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void main​(java.lang.String[] args)  
      static boolean[] solve​(int[] profit, int[] weight, int W)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Knapsack01DynamicOneSolution

        public Knapsack01DynamicOneSolution()
    • Method Detail

      • solve

        public static boolean[] solve​(int[] profit,
                                      int[] weight,
                                      int W)
      • main

        public static void main​(java.lang.String[] args)