package lanqiao.improve; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class BAshoes { public static int ba(int m,int n){ int[][] result = new int[m+1][n+1];//解决了困扰我许久的问题。定义数组都是定义m+1。是为了递推方程的判断的时候不会出现数组越界。 for(int i =1;i<=m;i++){ result[i][0] = 1; for(int j =1;j<=n;j++){ if(i >= j){ result[i][j] = result[i-1][j] + result[i][j-1]; } } } return result[m][n]; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] strs = br.readLine().split(" "); int m = Integer.parseInt(strs[0]); int n = Integer.parseInt(strs[1]); System.out.println(ba(m,n)); } }
原文:https://www.cnblogs.com/mushuise/p/11632348.html