标签:static detail img csdn article png inf int com
请编写一个函数(允许增加子函数),计算n x m的棋盘格子(n为横向的格子数,m为竖向的格子数)沿着各自边缘线从左上角走到右下角,总共有多少种走法,要求不能走回头路,即:只能往右和往下走,不能往左和往上走。
private static void calc(int row, int col) {
int[][] arr = new int[row + 1][col + 1];
for (int i = 0; i <= col; i++) {
arr[0][i] = 1;
}
for (int i = 0; i <= row; i++) {
arr[i][0] = 1;
}
for (int i = 1; i <= row; i++) {
for (int j = 1; j <= col; j++) {
arr[i][j] = arr[i - 1][j] + arr[i][j - 1];
}
}
System.out.println(arr[row][col]);
}
借鉴:https://blog.csdn.net/qq_41071068/article/details/103079592
标签:static detail img csdn article png inf int com
原文地址:https://www.cnblogs.com/dongma/p/13222720.html