This is also a question asked by netizens when answering questions. m of the same apple is put on n identical dishes, and the arrangement and combination method is not easy to deal with because of the same. There are many ideas for solving this problem. Here is a better understanding of the solution: ① At least one plate is put, so that at least one plate, n first put n dishes, the remaining m-n can be randomly placed. ② the minimum number of dishes is not put. In this way, the remaining n-1 dishes can still be implemented using m code:
Import java. util. role; public class MNAppleTest {public static void main (String [] args) {role in = new role (System. in); int N, M; // M Apple, N Disk M = in. nextInt (); N = in. nextInt (); System. out. print ("Total" + cal (M, N) + "result");} private static int cal (int m, int n) {if (m <0) return 0; if (m = 0 | n = 1) return 1; return cal (m-n, n) + cal (m, n-1 );}}
Enter 10, 20, and press ENTER 1020. There are 42 results