Topic description
There is an X*Y grid, and the small group has to move from the upper left corner to the lower right corner on this grid, and can only go to the grid point and only to the right or down. Please design an algorithm to calculate how many ways a small group can move. Given two positive integers int x, int y, return the number of moves in the clique.
Enter description:
The input consists of one line, two positive integers x and y separated by commas, in the range [1,10].
Output description:
The output consists of one line, the number of moves.
Example 1
enter
3 2
output
10
1 import java.util.Scanner; 2 /** 3 * the number of grid moves 4 * m*n grids have to go in total of m+n steps 5 * calculation of the number of permutations and combinations 6 * take out m from m+n or How many ways are there to find n? 7 * !(m+n)/!n 8 * @author Dell 9 * 10 */ 11 public class Main { 12 static long getNFactorial( int n) { 13 if (n==0 ) { 14 return 1l ; 15 } else { 16 return n*getNFactorial(n-1); 17 } 18 } 19 static long getCombination(int m ,int n) { 20 long a = 1; 21 for (int i = 0; i <n ; i++) { 22 a*=m; 23 m--; 24 } 25 return a/getNFactorial(n); 26 } 27 public static void main(String[] args) { 28 Scanner sc = new Scanner(System.in); 29 int m =sc.nextInt(); 30 int n = sc.nextInt(); 31 int a = Math.min(m, n); 32 long res = getCombination(m+n, n); 33 System.out.println(res); 34 } 35 }