题解 | #走方格的方案数#

走方格的方案数

http://www.nowcoder.com/practice/e2a22f0305eb4f2f9846e7d644dba09b

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    static int count = 0;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] rcs = br.readLine().split(" ");
        int[][] grid = new int[Integer.parseInt(rcs[0])+1][Integer.parseInt(rcs[1])+1];
        go(grid,0,0);
        System.out.println(count);
    }

    public static void go(int[][] rcs,int row,int col){
        if (row == rcs.length-1 && col == rcs[row].length-1){
            count++;
        }else {
            if (row == rcs.length-1){
                go(rcs,row,col+1);
            }else if (col == rcs[row].length-1){
                go(rcs,row+1,col);
            }else {
                go(rcs,row+1,col);
                go(rcs,row,col+1);
            }

        }
    }
}

全部评论

相关推荐

10-29 18:20
济南大学 Java
用微笑面对困难:他不是人事吗,怎么净特么不干人事
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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