放苹果
放苹果
http://www.nowcoder.com/questionTerminal/bfd8234bb5e84be0b493656e390bdebf
import java.util.*; public class Main { // 计算放苹果方法的数目 private int count(int m, int n) { // 没有苹果或者只剩一个盘子 if (m == 0 || n == 1) return 1; // 盘子大于苹果, 则不考虑多出来的盘子 if (n > m) return count(m, m); return count(m, n-1) + count(m - n, n); } public Main() { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int m = in.nextInt(); int n = in.nextInt(); int result = -1; if (n >= 1 && n <= 10 && m >= 1 && m <= 10) { result = count(m, n); } System.out.println(result); } } public static void main(String[] args) { Main solution = new Main(); } }