Esempio n. 1
0
        private void RunUnlimited(int[] prices, int[] weights, int n, int totalWeight)
        {
            Console.WriteLine($"Weights: {string.Join(",", weights)}");
            Console.WriteLine($"Prices: {string.Join(",", prices)}");
            Knapsack knapsack = new Knapsack(prices, weights, n);

            int totalPrice = knapsack.PackUnlimitedWithRecur(totalWeight);

            Console.WriteLine($"PackUnlimitedWithRecur: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.PackUnlimited(totalWeight);
            Console.WriteLine($"PackUnlimited: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.PackUnlimitedExact(totalWeight);
            Console.WriteLine($"PackUnlimitedExact: {totalWeight} - {totalPrice}");
            Console.WriteLine();
        }
Esempio n. 2
0
        private void Run01(int[] prices, int[] weights, int n, int totalWeight)
        {
            Console.WriteLine($"Weights: {string.Join(",", weights)}");
            Console.WriteLine($"Prices: {string.Join(",", prices)}");
            Knapsack knapsack = new Knapsack(prices, weights, n);

            int totalPrice = knapsack.Pack01WithRecur(totalWeight);

            Console.WriteLine($"Pick01WithRecur: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.Pack01(totalWeight);
            Console.WriteLine($"Pick01: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.Pack01WithOpt(totalWeight);
            Console.WriteLine($"Pack01WithOpt: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.Pack01WithOpt1(totalWeight);
            Console.WriteLine($"Pack01WithOpt1: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.Pack01Exact(totalWeight);
            Console.WriteLine($"Pick01Exact: {totalWeight} - {totalPrice}");
            totalPrice = knapsack.Pack01ExactWithOpt(totalWeight);
            Console.WriteLine($"Pack01ExactWithOpt: {totalWeight} - {totalPrice}");
            Console.WriteLine();
        }