两种解法
int fun19(int n, int m) { if (n == 0) return 1; if (m == 0) return 0; if (m > n) return fun19(n, n); else return fun19(n, m - 1) + fun19(n - m, m); } int main(void) { int a[15][15] = { 0 }; for (int i = 1; i < 15; i++) { a[0][i] = 1; // 0个苹果 a[i][0] = 0; // 0个篮子 } for (int n = 1; n < 15; n++) { for (int m = 1; m < 15; m++) { if (m > n) a[n][m] = a[n][n]; else a[n][m] = a[n][m - 1] + a[n - m][m]; } } int M, N, k; printf("请输入有几个苹果并回车:"); scanf("%d", &M); printf("请输入有几个篮子并回车:"); scanf("%d", &N); //k = a[M][N]; //动态规划 k = fun19(M, N); // 递归 printf("%d\n", k); system("pause"); return 0; }
来源:https://www.cnblogs.com/asdfknjhu/p/12344842.html