题解 | 放苹果

放苹果

https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 苹果数量
        int x = in.nextInt();
        // 盘子数量
        int y = in.nextInt();

        System.out.println(calc(x, y));

    }
    private static int calc(int x, int y) {
        if (x <= 1 || y <= 1) {
            return 1;
        } else if (y > x) {
            return calc(x, x);
        } else {
            return calc(x, y - 1) + calc(x - y, y);
        }
    }
}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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