Exemple #1
0
        public MinimumPathSum()
        {
            Console.WriteLine("Minimum Path Sum :");

            int[][] grid = new int[20][];
            grid[0]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[1]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[2]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[3]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[4]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[5]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[6]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[7]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[8]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[9]  = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[10] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[11] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[12] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[13] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[14] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[15] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[16] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[17] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[18] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };
            grid[19] = new int[] { 7, 1, 3, 5, 8, 9, 9, 2, 1, 9, 0, 8, 3, 1, 6, 6, 9, 5, 7 };

            DepthFirstSearch dfs  = new DepthFirstSearch();
            Iterate2D        loop = new Iterate2D();
            DFSArrayMemo     am   = new DFSArrayMemo();

            var watch = System.Diagnostics.Stopwatch.StartNew();

            Console.WriteLine(am.MinPathSum(grid));
            watch.Stop();
            var elapsedMs = watch.ElapsedMilliseconds;

            Console.WriteLine("elapsed time : " + elapsedMs.ToString());
            Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            //TreeNode v0 = new TreeNode(0);
            //TreeNode v1 = new TreeNode(1);
            //TreeNode v2 = new TreeNode(2);
            //TreeNode v3 = new TreeNode(3);
            //TreeNode v4 = new TreeNode(4);
            //TreeNode v5 = new TreeNode(5);
            //TreeNode v6 = new TreeNode(6);
            //TreeNode v7 = new TreeNode(7);

            //v4.left = v2;
            //v4.right = v5;
            //v2.left = v1;
            //v2.right = v3;
            //v1.left = v0;
            //v5.right = v6;
            //v6.right = v7;

            //v1.left = v2;
            //v1.right = v3;
            //v2.left = v4;
            //v2.right = v5;

            //v1.right = v2;
            //v2.left = v3;

            //int step = Recursion.DiameterOfBinaryTree(v1);


            //var result = Math.Reverse(-2147483648);

            //var result = String.CompressString('abbccd');

            //MyStack stack = new MyStack();
            //stack.Push(1);
            //stack.Push(2);
            //stack.Push(3);
            //stack.Push(4);

            //var num4 = stack.Pop();
            //var num3 = stack.Pop();
            //var num2 = stack.Pop();
            //var num1 = stack.Pop();

            //int{}{} grid1 = {new{} {2, 1, 1}, new{} {1, 1, 0}, new{} {0, 1, 1}};

            //int{}{} grid2 = {new{} {2, 1, 1}, new{} {0, 1, 1}, new{} {1, 0, 1}};

            //int{}{} grid3 = {new{} {2, 1, 0, 2}};

            //int{}{} grid4 = {new{} {1}, new{} {1}, new{} {1}, new{} {1}};

            //int result1 = Hashtable.OrangesRotting(grid1);

            //int result2 = Hashtable.OrangesRotting(grid2);

            //int result3 = Hashtable.OrangesRotting(grid3);

            //int result4 = Hashtable.OrangesRotting(grid4);


            //var result = Heap.GetLeastNumbers(new{} {3, 2, 1, 5, 7, 6, 9, 2}, 2);

            //var result = SlidingWindow.MinWindow('a', 'aa');

            //int x = 9;

            //Console.WriteLine(x % 2);
            //Console.WriteLine(x & (2-1));

            char[][] board =
            {
                new[] { '.', '.', '.', '.', '.', '.', '.', '.' },
                new[] { '.', '.', '.', 'p', '.', '.', '.', '.' },
                new[] { '.', '.', '.', 'p', '.', '.', '.', '.' },
                new[] { 'p', 'p', '.', 'R', '.', 'p', 'B', '.' },
                new[] { '.', '.', '.', '.', '.', '.', '.', '.' },
                new[] { '.', '.', '.', 'B', '.', '.', '.', '.' },
                new[] { '.', '.', '.', 'p', '.', '.', '.', '.' },
                new[] { '.', '.', '.', '.', '.', '.', '.', '.' }
            };
            DepthFirstSearch.NumRookCaptures(board);
        }