//SOL
        public static BigInteger CalcPermutations(int[,] mat)
        {
            if (mat[0, 0] == 1 || mat[mat.GetLength(0) - 1, mat.GetLength(1) - 1] == 1)
            {
                return(0);
            }
            BigInteger Ways = Unique_Paths.Num_ways(mat.GetLength(0), mat.GetLength(1));

            for (int i = 0; i < mat.GetLength(0); i++)
            {
                for (int j = 0; j < mat.GetLength(1); j++)
                {
                    if (mat[i, j] != 1)
                    {
                        continue;
                    }
                    bool b1 = (i == 0 || i == mat.GetLength(0) - 1);
                    bool b2 = (j == 0 || j == mat.GetLength(1) - 1);
                    if (b2 && b1)
                    {
                        Ways -= 1;                  //IsCorner
                    }
                    else if (b1 ^ b2)
                    {
                        Ways -= 2;                  //IsBorder
                    }
                    else
                    {
                        Ways -= 4;                  //IsMiddle
                    }
                }
            }
            return(Ways);
        }
示例#2
0
        public void UniquePathsTests()
        {
            Unique_Paths obj = new Unique_Paths();

            var x = obj.UniquePaths(3, 2); //3

            x = obj.UniquePaths(7, 3);     //28

            x = obj.UniquePaths(1, 1);     //1

            x = obj.UniquePaths(0, 1);     //0
        }