Current location - Training Enrollment Network - Mathematics courses - A Mathematical Problem of C++ Programming
A Mathematical Problem of C++ Programming
This can be directly calculated by a set of formulas. You don't have to try one by one. Why write a program? ......

First, N>= M*K

First, determine how much to put in each box. We have arranged n positions, of which 1~K is used for box 1 and K+ 1 ~ 2K is used for box2 ... so the first M*K positions are assigned to fixed positions of m boxes;

Then, there are N-M*K positions left, and we consider M- 1 "partition" together with these "positions". On X = (N-M*K)+(M- 1) spaces, we can arrange any M- 1 spaces as "partition".

C( N-M*k+M- 1, M- 1) combinations. .....

In the above picture, the position in front of the first partition is box 1, and the position in front of the second partition is box2 ... and the position behind the last partition is boxM.

Finally, let's fill all the N balls P(N, n), and then fill in the above division in turn, and it's ok.

In this way, there are: p (n, n) * c (n-m * k+m- 1, m- 1) in different ways. .....

Maybe you don't have to write a program to work hard. .....

The core of computer science is mathematics, and only incompetent programmers will do everything regardless of algorithms. .....