Created
March 7, 2026 12:08
-
-
Save thinkphp/9f3c7bdb2b95ee175f1288e580e8e480 to your computer and use it in GitHub Desktop.
permutari_rec.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #define SIZE 100 | |
| using namespace std; | |
| int stack[SIZE],n; | |
| int ok(int k) { | |
| for(int i = 1; i < k; ++i) { | |
| if(stack[i] == stack[k]) return 0; | |
| } | |
| return 1; | |
| } | |
| //k = 2 | |
| void bkt( int k ) { | |
| for(int i = 1; i <= n; ++i) { | |
| stack[ k ] = i;//stack[1] = 1;stack[2] = 2; stack[3] = 3 | |
| if( ok( k ) ) { | |
| if( k == n ) { | |
| for(int i = 1; i <= n; ++i) cout<<stack[i]<<" ";//1 2 3 | |
| cout<<endl; | |
| } else { | |
| bkt( k + 1 );//3 | |
| } | |
| } | |
| } | |
| } | |
| int main(int argc, char const *argv[]) | |
| { | |
| cin>>n; | |
| bkt( 1 ); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment