示例#1
0
        public int UniquePaths(int m, int n)
        {
            HJPoint initalPoint = new HJPoint(0, n - 1);
            HJSize  map         = new HJSize(m, n);

            PointStack.Push(initalPoint);

            do
            {
                var curPoint = PointStack.Pop();

                if (curPoint.X == map.Width - 1 && curPoint.Y == 0)
                {
                    ++RouteCounts;
                    continue;
                }
                var rightPoint = new HJPoint(curPoint.X + 1, curPoint.Y);
                var belowPoint = new HJPoint(curPoint.X, curPoint.Y - 1);
                if (map.Contains(rightPoint))
                {
                    PointStack.Push(rightPoint);
                }
                if (map.Contains(belowPoint))
                {
                    PointStack.Push(belowPoint);
                }
            } while (PointStack.Count != 0);

            return(RouteCounts);
        }
示例#2
0
 public bool Contains(HJPoint point)
 {
     if (point.X < Width && point.Y < Height && point.X >= 0 && point.Y >= 0)
     {
         return(true);
     }
     return(false);
 }