ThisIn fact, it is very simple to put M identical apples on the same plate and ask how many ways to put them.
I want to make some changes to this question first. If it is placed on different dishes, the result will be X1 + X2 + X3 +... + Xn = the number of M solutions. A combination of mathematics is called a combination of multiple sets.
If the plate is different and the plate is not empty, this is an ordered split of integers. That is, the result that appears at least once in the combination of multiple sets.
In this question, the plates are the same, that is, the unordered splitting of integers.
The k splitting of n means dividing N into k numbers greater than 0.
The unordered division of integers has a formula: B (n + k, K) = B (n, 1) + B (n, 2) + B (n, 3) ~~~ B (n, k );
Where, the K split of the B (n, k) Table is N.
I'm going to attend classes. paste it.Code:
# Include <iostream> # include <stdio. h> # include <string. h> using namespace STD; int data [30] [30]; int get (int m, int K) {If (data [m] [k]! =-1) return data [m] [k]; If (K = 1 | M = k) return 1; if (M <k) return 0; int sum = 0; For (INT I = 1; I <= K; I ++) {sum + = get (m-K, I );} data [m] [k] = sum; return sum;} int main () {int t; CIN> T; memset (data,-1, sizeof (data )); while (t --) {int M, K; CIN> m> K; int sum = 0; For (INT I = 1; I <= K; I ++) sum + = get (M, I); cout <sum <"\ n";} return 0 ;}