// Input 8 12.61 s consumed // input 8 11.72 s consumed remove '-' in the printed array # include <stdio. h> # include <string. h> # include <stdlib. h> # define length 27 int n = 0; void permute (INT [], Int, INT); void swapint (Int & A, Int & B ); void printintarray (INT [], INT); // function implementation void swapint (Int & A, Int & B) {int temp; temp = A; A = B; B = temp;} void printintarray (INT target [], int length) {int I; for (I = 0; I <length; I ++) printf ("% d", target [I]); printf ("\ n");} void permute (INT target [], int begin, int end) {If (begin = END) {printintarray (target, end + 1); N ++; return;} int I; for (I = begin; I <= end; I ++) {swapint (target [begin], target [I]); permute (target, begin + 1, end); swapint (target [begin], target [I]) ;}}// test functions void testpermute () {int Len; scanf ("% d", & Len); int * testcase = (int *) malloc (LEN * sizeof (INT); int I; for (I = 0; I <Len; I ++) testcase [I] = I + 1; permute (testcase, 0, len-1);} // main function void main () {testpermute (); printf ("n = % d", n );}
z_yd@tom.com