Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.49 KB | None | 0 0
  1. #include <cstdio>
  2.  
  3. using namespace std;
  4.  
  5. int a[1000], bio[1000], z[1000];
  6. int n;
  7.  
  8. void rec( int r ) {
  9.   if( r == n ) {
  10.     for( int i = 0; i < n; ++i )
  11.       printf( "%d ", z[i] );
  12.     putchar( '\n' );
  13.     return;
  14.   }
  15.  
  16.   for( int x = 0; x < n; ++x )
  17.     if( bio[x] == 0 ) {
  18.       bio[x] = 1, z[r] = a[x];
  19.       rec( r+1 );
  20.       bio[x] = 0;
  21.     }
  22. }
  23.  
  24. int main( void ) {
  25.   scanf( "%d", &n );
  26.   for( int i = 0; i < n; ++i )
  27.     scanf( "%d", a+i );
  28.  
  29.   rec( 0 );
  30.   return 0;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement