Пример #1
0
        public static int GetMaximumSumSubrectangle(int [,] arr, int rows, int cols, out int max_left, out int max_right, out int max_up, out int max_down)
        {
            int[] temp = new int[rows];
            int   curr_max, max = arr[0, 0];

            max_left = max_right = max_up = max_down = 0;

            int curr_max_up, curr_max_down = 0;

            for (int Left = 0; Left < cols; Left++)
            {
                Array.Clear(temp, 0, rows);
                for (int Right = Left; Right < cols; Right++)
                {
                    for (int row = 0; row < rows; row++)
                    {
                        temp[row] += arr[row, Right];
                    }
                    curr_max = MaxSumSubArray_Kadane.GetMaxSumSubArray_Kadane(temp.ToList(), out curr_max_up, out curr_max_down);
                    if (max < curr_max)
                    {
                        max       = curr_max;
                        max_up    = curr_max_up;
                        max_down  = curr_max_down;
                        max_left  = Left;
                        max_right = Right;
                    }
                }
            }
            return(max);
        }
Пример #2
0
        static void Main(string[] args)
        {
            while (true)
            {
                Console.Write("\n\t1.LongestCommonPrefix\n\t2.PhoneNumberLetterCombination");
                Console.Write("\n\t4.TwoSum\n\t5.TwoSumIV_Input_BST\n\t6.SearchAutoComplete\n\t7.SubTree");
                Console.Write("\n\t8.Decode Ways\n\t9.AveregeOfLevelsBinaryTree\n\t10.Brick Wall");
                Console.Write("\n\t11.Binary Tree Diameter\n\t12.TargetSum\n\t13.Hamming Distance");
                Console.Write("\n\t14.TotalHammingDistance\n\t15.BuyAndSellStock\n\t16.SortedArrayToBalancedBST");
                Console.Write("\n\t17.MinimumLengthSubArraySum\n\t18.MaxSumSubArray_Kadane\n\t19.MaximumSumSubrectangle");
                Console.Write("\n\t20.LongestContinuousIncreasingSubsequence\n\t21.Burst Ballons\n\t22.MinimumWindowSubstring");
                Console.Write("\n\t23.<moved>\n\t24.PlusOne");
                Console.Write("\n\t27.ExclusiveTimeOfFunctions");
                Console.Write("\n\t28.VericalOrderTraversal");

                Console.Write("\n\t0:Exit\nEnter Choice: ");

                var input = Console.ReadLine();
                switch (input)
                {
                case "1":
                    LongestCommonPrefix.Demo();
                    break;

                case "2":
                    PhoneNumberLetterCombination.Demo();
                    break;

                case "4":
                    TwoSum.Demo2();
                    break;

                case "5":
                    TwoSumIV_Input_BST.Demo();
                    break;

                case "6":
                    SearchAutoComplete.Demo();
                    break;

                case "7":
                    SubTree.Demo();
                    break;

                case "8":
                    DecodeWays.Demo();
                    break;

                case "9":
                    AveregeOfLevelsBinaryTree.Demo();
                    break;

                case "10":
                    BrickWall.Demo();
                    break;

                case "11":
                    BinaryTreeDiameter.Demo();
                    break;

                case "12":
                    TargetSum.Demo();
                    break;

                case "13":
                    HammingDistance.Demo();
                    break;

                case "14":
                    TotalHammingDistance.Demo();
                    break;

                case "15":
                    BuyAndSellStock.Demo();
                    break;

                case "16":
                    SortedArrayToBalancedBST.Demo();
                    break;

                case "17":
                    MinimumLengthSubArraySum.Demo();
                    break;

                case "18":
                    MaxSumSubArray_Kadane.Demo();
                    break;

                case "19":
                    MaximumSumSubrectangle.Demo();
                    break;

                case "20":
                    LongestContinuousIncreasingSubsequence.Demo();
                    break;

                case "21":
                    BurstBallons.Demo();
                    break;

                case "22":
                    MinimumWindowSubstring.Demo();
                    break;

                //case "23":
                //    MultiplyStrings.Demo();
                //    break;
                case "24":
                    PlusOne.Demo();
                    break;

                case "27":
                    ExclusiveTimeOfFunctions.Demo();
                    break;

                case "28":
                    VericalOrderTraversal.Demo();
                    break;

                case "0":
                    return;
                }

                Console.WriteLine("Press any key to continue...");
                Console.ReadKey();
            }
        }