[Java] Blue Bridge recursive calculation basis of the total number of species moves

Calculated from a position (x, y) went to (0,0) a total of how many moves

Code:

package xn.zzunit.recurrence;

/**
 * 从某个位置(x,y)走到(0,0) 一共多少种走法
 * @author tyrantForever
 *
 */
public class Project3 {

	public static void main(String[] args) {
		System.out.println(methord(1,1));
	}
	
	public static int methord(int x, int y) {
		if(x == 0 || y == 0) {
			return 1;
		}
		return methord(x - 1,y) + methord(x, y - 1);
	}

}

Note:

(1) The main idea of ​​this question is: if x or y is 0 then go to (0,0) only one way of

 

 

 

Published 130 original articles · won praise 37 · views 10000 +

Guess you like

Origin blog.csdn.net/tyrant_forever/article/details/104397323