M identical apples are placed on n identical dishes. The arrangement and combination method is not easy to handle because they are the same. This problem has plagued me for a long time. Finally, the great god "missing" gave the answer: put eight apples on three dishes as an example: 8 apple 3 plate = 8 Apple 2 plate + 5 Apple 2 plate (1 plate per disk) + 2 Apple 2 plate (3 plates per disk) = (8 Apple, 1 plate + 6 apple, 1 plate (each disk already has one) + (3 Apple, 1 plate (each disk already has one) + 1 Apple, 1 plate) (one for each disk) + (one apple and one plate for each disk) + one apple and one plate for each disk (three for each disk )... = 5 + 3 + 2 = 10 Programming implementation:
# Include <iostream> # include <string> using namespace std; int func (int m, int n) {cout <"m =" <m <", n = "<n <endl; if (n <= 1) return 1; int t = 0; for (int I = m; I> = 0; i-= n) {t + = func (I, n-1);} return t;} int main () {int m = 0, n = 0; while (1) {cout <"Enter the number of plates for Apple:"; cin> m> n; cout <"you entered: m = "<m <n <endl; if (m =-1) {break;} cout <" Total "<func (m, n, "--") <"seeding method" <endl; cout <"------------" <endl;} return 0 ;}
Computing Result: here, I am deeply grateful to you for your lack of experience!