Esempio n. 1
0
        public void Test()
        {
            BalancePartition partition = new BalancePartition();

            int[] nums;
            int   sum;

            sum  = 10;
            nums = new int[] { 3, 7, 4, 6 };
            Test(partition, nums, sum);
            sum  = 5;
            nums = new int[] { 1, 1, 1, 3, 2, 2 };
            Test(partition, nums, sum);
            sum  = 10;
            nums = new int[] { 3, 2, 1, 1, 6, 7 };
            Test(partition, nums, sum);
            sum  = 11;
            nums = new int[] { 3, 2, 1, 1, 6, 8 };
            Test(partition, nums, sum);
            sum  = 6;
            nums = new int[] { 3, 2, 5 };
            Test(partition, nums, sum);

            nums = new int[] { 66, 90, 7, 6, 32, 16, 2, 78, 69, 88, 85, 26, 3, 9, 58, 65, 30, 96, 11, 31, 99, 49, 63, 83, 79, 97, 20, 64, 81, 80, 25, 69, 9, 75, 23, 70, 26, 71, 25, 54, 1, 40, 41, 82, 32, 10, 26, 33, 50, 71, 5, 91, 59, 96, 9, 15, 46, 70, 26, 32, 49, 35, 80, 21, 34, 95, 51, 66, 17, 71, 28, 88, 46, 21, 31, 71, 42, 2, 98, 96, 40, 65, 92, 43, 68, 14, 98, 38, 13, 77, 14, 13, 60, 79, 52, 46, 9, 13, 25, 8 };
            Test(partition, nums, 2387);

            // Test(partition, new int[] { 100 }, 50);
        }
Esempio n. 2
0
        private void Test(BalancePartition partition, int[] nums, int sum)
        {
            bool isSubsetWithRecur = partition.IsSubsetSumWithRecur(nums, sum);
            bool isSubset          = partition.IsSubsetSum1(nums, sum);

            Console.WriteLine($"{string.Join(",", nums)} for {sum} can be balance partition: {isSubset} and {isSubsetWithRecur}(Recur)");
        }