36 lines
800 B
C++
36 lines
800 B
C++
|
#include <stdio.h>
|
|||
|
#include <stdlib.h>
|
|||
|
|
|||
|
void PrintPartitions(int n, int max, int* partition, int index) {
|
|||
|
// <20><EFBFBD><F2A5BBB1>p
|
|||
|
if (n == 0) {
|
|||
|
// <20><> n <20><> 0 <20>ɡA<C9A1><41><EFBFBD>ܧ<EFBFBD><DCA7><EFBFBD><EFBFBD>@<40>ؤ<EFBFBD><D8A4>Τ覡<CEA4>A<EFBFBD><41><EFBFBD>X<EFBFBD><58><EFBFBD>G
|
|||
|
for (int i = 0; i < index; i++) {
|
|||
|
printf("%d", partition[i]);
|
|||
|
if (i < index - 1) {
|
|||
|
printf(" ");
|
|||
|
}
|
|||
|
}
|
|||
|
printf("\n");
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
// <20><><EFBFBD>j<EFBFBD><6A><EFBFBD>p
|
|||
|
for (int i = (max > n) ? n : max; i >= 1; i--) {
|
|||
|
partition[index] = i;
|
|||
|
PrintPartitions(n - i, i, partition, index + 1);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
int main() {
|
|||
|
int num;
|
|||
|
printf("<EFBFBD><EFBFBD><EFBFBD>J<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ==> ");
|
|||
|
scanf("%d", &num);
|
|||
|
|
|||
|
int* partition = (int*) calloc(num, sizeof(int));
|
|||
|
PrintPartitions(num, num, partition, 0);
|
|||
|
|
|||
|
free(partition);
|
|||
|
return 0;
|
|||
|
}
|