题解 | #放苹果#
放苹果
https://www.nowcoder.com/practice/bfd8234bb5e84be0b493656e390bdebf
#include <stdio.h> int apples(int m, int n){ if(m == 0 || n == 1){ return 1; ////没有苹果的时候方法只有1种 }else if (m < n) { return apples(m, m); //如果盘子比苹果多,即m>n,那么肯定有m-n个空盘子,空盘子没用,直接不要 }else{ return apples(m, n-1) + apples(m - n, n); } } int main() { int m, n; scanf("%d%d", &m, &n); printf("%d", apples(m, n)); }