1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <stdlib.h> #include <stdio.h> void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } void printArray(int *a, int length) { printf("["); int i; for (i = 0; i < length; i++) { printf("%d",a[i]); if (i != length - 1) printf(", "); } printf("]\n"); } void combinations(int *array,int n,int i,int *currSol,int length) { if (length == i){ printArray(currSol,length); return; } int j; for (j = 0; j < n; j++) { currSol[i] = array[j]; combinations(array,n,i+1,currSol,length); } return; } int main() { int arr[] = {1,2,3}; int sol[4]; combinations(arr,3,0,sol,4); return 0; } |
I2luY2x1ZGUgPHN0ZGxpYi5oPgojaW5jbHVkZSA8c3RkaW8uaD4Kdm9pZCBzd2FwKGludCogYSwgaW50KiBiKSB7IAogIGludCB0ZW1wID0gKmE7CiAgKmEgPSAqYjsKICAqYiA9IHRlbXA7Cn0Kdm9pZCBwcmludEFycmF5KGludCAqYSwgaW50IGxlbmd0aCkgeyAKICBwcmludGYoIlsiKTsKICBpbnQgaTsKICBmb3IgKGkgPSAwOyBpIDwgbGVuZ3RoOyBpKyspIHsgCiAgICBwcmludGYoIiVkIixhW2ldKTsKICAgIGlmIChpICE9IGxlbmd0aCAtIDEpIHByaW50ZigiLCAiKTsKICB9CiAgcHJpbnRmKCJdXG4iKTsKfQp2b2lkIGNvbWJpbmF0aW9ucyhpbnQgKmFycmF5LGludCBuLGludCBpLGludCAqY3VyclNvbCxpbnQgbGVuZ3RoKSB7IAogIGlmIChsZW5ndGggPT0gaSl7CiAgICAgcHJpbnRBcnJheShjdXJyU29sLGxlbmd0aCk7CiAgICAgcmV0dXJuOwogIH0KICBpbnQgajsKICBmb3IgKGogPSAwOyBqIDwgbjsgaisrKSB7IAogICAgIGN1cnJTb2xbaV0gPSBhcnJheVtqXTsKICAgICBjb21iaW5hdGlvbnMoYXJyYXksbixpKzEsY3VyclNvbCxsZW5ndGgpOwogIH0KICByZXR1cm47Cn0KIAppbnQgbWFpbigpIHsgCmludCBhcnJbXSA9IHsxLDIsM307CmludCBzb2xbNF07CmNvbWJpbmF0aW9ucyhhcnIsMywwLHNvbCw0KTsKcmV0dXJuIDA7Cn0=
-
upload with new input
-
result: Success time: 0.01s memory: 1676 kB returned value: 0
[1, 1, 1, 1] [1, 1, 1, 2] [1, 1, 1, 3] [1, 1, 2, 1] [1, 1, 2, 2] [1, 1, 2, 3] [1, 1, 3, 1] [1, 1, 3, 2] [1, 1, 3, 3] [1, 2, 1, 1] [1, 2, 1, 2] [1, 2, 1, 3] [1, 2, 2, 1] [1, 2, 2, 2] [1, 2, 2, 3] [1, 2, 3, 1] [1, 2, 3, 2] [1, 2, 3, 3] [1, 3, 1, 1] [1, 3, 1, 2] [1, 3, 1, 3] [1, 3, 2, 1] [1, 3, 2, 2] [1, 3, 2, 3] [1, 3, 3, 1] [1, 3, 3, 2] [1, 3, 3, 3] [2, 1, 1, 1] [2, 1, 1, 2] [2, 1, 1, 3] [2, 1, 2, 1] [2, 1, 2, 2] [2, 1, 2, 3] [2, 1, 3, 1] [2, 1, 3, 2] [2, 1, 3, 3] [2, 2, 1, 1] [2, 2, 1, 2] [2, 2, 1, 3] [2, 2, 2, 1] [2, 2, 2, 2] [2, 2, 2, 3] [2, 2, 3, 1] [2, 2, 3, 2] [2, 2, 3, 3] [2, 3, 1, 1] [2, 3, 1, 2] [2, 3, 1, 3] [2, 3, 2, 1] [2, 3, 2, 2] [2, 3, 2, 3] [2, 3, 3, 1] [2, 3, 3, 2] [2, 3, 3, 3] [3, 1, 1, 1] [3, 1, 1, 2] [3, 1, 1, 3] [3, 1, 2, 1] [3, 1, 2, 2] [3, 1, 2, 3] [3, 1, 3, 1] [3, 1, 3, 2] [3, 1, 3, 3] [3, 2, 1, 1] [3, 2, 1, 2] [3, 2, 1, 3] [3, 2, 2, 1] [3, 2, 2, 2] [3, 2, 2, 3] [3, 2, 3, 1] [3, 2, 3, 2] [3, 2, 3, 3] [3, 3, 1, 1] [3, 3, 1, 2] [3, 3, 1, 3] [3, 3, 2, 1] [3, 3, 2, 2] [3, 3, 2, 3] [3, 3, 3, 1] [3, 3, 3, 2] [3, 3, 3, 3]


