题解 | #走方格的方案数#
走方格的方案数
https://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
import java.util.Scanner; public class Main { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int cols = sc.nextInt() + 1; int rows = sc.nextInt() + 1; int[][] arr = new int[rows][cols]; for (int i = 0; i < rows; i++) { arr[i][0] = 1; } for (int j = 1; j < cols; j++) { arr[0][j] = 1; } for (int i = 1; i < rows; i++) { for (int j = 1; j < cols; j++) { arr[i][j] = arr[i - 1][j] + arr[i][j - 1]; } } System.out.println(arr[rows - 1][cols - 1]); } }