コード例 #1
0
        //http://www.es.ele.tue.nl/education/5MC10/Solutions/knapsack.pdf
        public void Knapsack_DPMethod2()
        {
            int expectMaxValue = 90;
            int capacity       = 10;

            int[] weights = { 5, 4, 6, 3 };
            int[] values  = { 10, 40, 30, 50 };

            IV.Knapsack_0_1.Result r = IV.Knapsack_0_1.Knapsack_DP(capacity, weights, values, weights.Length);
            Assert.AreEqual(expectMaxValue, r.maxValue);
        }
コード例 #2
0
        public void Knapsack_RecursiveTestMethod()
        {
            int expectMaxValue = 220;

            int capacity = 50;

            int[] weights = { 10, 20, 30 };
            int[] values  = { 60, 100, 120 };

            IV.Knapsack_0_1.Result r = IV.Knapsack_0_1.Knapsack_Recursive(capacity, weights, values, weights.Length);
            Assert.AreEqual(expectMaxValue, r.maxValue);
        }