Http://poj.org/problem? Id = 1664
This question can be done recursively. I want to put the apple in the first dish from (0 to m) and then to the second one, to ensure that each production method is different, the apple placed in the second one cannot start from 0. Otherwise, the same method will be generated, and the third and fourth plates .... Another problem is that there may be a lot of apples on the last plate. What should I do ?? All put in the last one ?? In fact, this is not the case. It may start with the previous situation. Therefore, you must ensure that this situation cannot be generated during the placement process. (y/(n-x)> = I) this line of code ensures that, because the number of apples in the plate is not decreasing, the number of I remaining dishes, as long as the number of remaining apples divided by the number of remaining dishes is not less than the number of apples on the current plate, we can ensure that this meets the requirements.
// 2013-06-27-14.39 # include <stdio. h> # include <string. h> int n, m, ans; int num [11]; void DFS (int x, int y) {If (x = N) {If (Y> = num [n-1]) ans ++;} else {for (INT I = num [x-1]; I <= Y & (y/(n-x)> = I); I ++) {num [x] = I; DFS (x + 1, y-I) ;}}int main () {int t; scanf ("% d", & T); While (t --) {memset (Num, 0, sizeof (Num); scanf ("% d", & M, & N); ans = 0; DFS (1, M ); printf ("% d \ n", ANS);} return 0 ;}