街道网络路径数目计算


代码:

#include <iostream>

#include <cassert>
using namespace std;
int numOfPaths(int divRow, int divCol)
{
    if(divRow == 0 || divCol == 0)
    {
        return 1;
    }
    else
    {
        return numOfPaths(divRow - 1, divCol) + numOfPaths(divRow, divCol -1);
    }
}
int main()
{
    int startRow, startCol, endRow, endCol;
    
    cout << "input start point:" << endl;
    cin >> startRow >> startCol;
    cout << "input end point:" << endl;
    cin >> endRow >> endCol;
    assert(startRow <= endRow || startCol <= endCol);
    cout << "PathCount :" << numOfPaths(endRow - startRow, endCol - startCol) << endl;
    return 0;
}

相关文章:

  • 2021-11-28
  • 2021-05-03
  • 2021-07-27
  • 2021-06-19
  • 2021-12-27
  • 2021-06-16
猜你喜欢
  • 2022-12-23
  • 2021-05-24
  • 2021-08-07
  • 2021-10-24
  • 2022-01-10
  • 2021-11-06
相关资源
相似解决方案