I can't even go to my blog. I am very depressed. I finally came once again. I saw someone who would put it out of the program that built with non-repetitive numbers, turned over the box, found. Put it out, for a long time, some places can't remember. There may be errors, please advise.
#include
#include
#define max_stack 128
INT Addends [MAX_STACK] = {0};
INT sp = 0;
INT used [max_stack] = {0};
INT GET_SUM (int SUM, int maxadde) {
INT i = 0;
INT Start = min (maxaddend, sum);
INT RET = 0;
IF (SUM == 0) {
For (i = SP-1; I> 0; --I)
Printf ("% d ", addends [i]);
Printf ("% d / n", addends [0]);
Ret = 1;
} else {
For (i = start; i> 0; --I) {
IF (USED [I]) Continue;
Addends [SP ] = i;
Used [i] = 1;
IF (! get_sum (sum-i, maxadde)) {
SP = 0;
Return 0;
}
--SP;
Ret = 1;
}
}
Return Ret;
}
INT Main (int Argc, char * argv []) {
INT M, N, I;
IF (argc! = 3) {
Printf ("INPUT The Sum (M) and the max addend (n), with space seperated:");
Scanf ("% D% D", & M, & n);
} else {
M = ATOI (Argv [1]);
n = atoi (argv [2]);
}
IF (m <= 0 || n <= 0 || m> = max_stack || n> = max_stack) Return 1;
For (; n> 0; - N) {
For (i = 0; i USED [I] = 0; GET_SUM (M, N); } System ("pause"); Return 0; } In fact, the previous procedure has added a global "whether it has used" symbol.