问题是要计算从m * n矩阵的左上角到右下角的所有可能路径,并限制从每个像元只能向右或向下移动的约束。
首先,请在此处阅读所陈述问题的各种可能解决方案
现在,对于最后一个解决方案,用于计算路径数的组合公式为m + n – 2 C m – 1 。让我们讨论该公式背后的数学。
Suppose we have an m*n matrix then according to the question we can only move right or down.
Here m = 5 and n = 3, we start from (0, 0) (i.e. start) and go to the end i.e. (4, 2) we can consider any one path lets say we choose
(0, 0) -> (0, 1) -> (0, 2) -> (1, 2) -> (2, 2) -> (3, 2) -> (4, 2)
Therefore, we moved 2 steps to the right and 4 steps downwards. Even if we take any other path same number of right and down steps will be required.
现在回想一下数学中的组合。正是在这里,我们有了路径而不是字母。在这里,我们必须涵盖到目的地的n-1 + m-1个蜂窝长度。
还记得我们正在向下移动m-1步,向右移动n-1步。因此,路径数本质上将是(m + n – 2)! /(n – 1)! *(m – 1)!它不过是m + n – 2 C n – 1或m + n – 2 C m – 1 。