题解 | #走方格的方案数#
走方格的方案数
http://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b
使用动态规划解决
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt(), n = scanner.nextInt();
int[][] dp = new int[m + 1][n + 1];
//dp[i][j] 表示到达交叉线i,j的走法
for(int i = 0; i <= m; i++){
dp[i][0] = 1;
}
for(int j = 0; j <=n; j++){
dp[0][j] = 1;
}
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
dp[i][j] = dp[i - 1][j] + dp[i][j - 1];
}
}
System.out.println(dp[m][n]);
}
}