题解 | 放苹果
放苹果
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);
}
}
}