2008年7月4日星期五

google tresure hunt 机器人

有一个机器人在36x36的格子上的左上角,移动到右下角,每次只能向下,或向右移动一步。

共有多少条路径?

这个问题很简单,组合数学中的问题。


Question

A robot is located at the top-left corner of a 36 x 36 grid (marked 'Start' in the diagram below).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked 'Finish' in the diagram below).

Note: The grid below is 7x3, and is used to illustrate the problem. It is not drawn to scale.

Robot

*Image not to scale.

How many possible unique paths are there?
(Note: Answer must be an exact, decimal representation of the number.)



解法:对于n x m的格子,路径数为组合中 n+m-2个数中n-1的组合数,

分析,机器人共需要走n+m-2步到达目的地。这些步中有n-1步是需要向右的。正好是组合数学中的组合定义。

数目可能比较大,会超出整形的最大值。编程的话,需要大数的支持。

有开源的一些项目可以使用。.net的话,可以用IntX codeplex上的项目。

没有评论: