网格走法数目

网格走法数目

http://www.nowcoder.com/questionTerminal/e27b9fc9c0ec4a17a5064fb6f5ab13e4

import java.util.*;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt(), y = sc.nextInt();
        System.out.println(f(x, y));
    }
    static int f(int x, int y){
        if(x == 0 || y == 0) return 1;   //撞墙之后,就只剩一条路倒着走了
        return f(x - 1, y) + f(x, y - 1);//从右下角往回倒着走
    }
}
全部评论

相关推荐

评论
2
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务