Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int n, m, result[10];
- bool check[10];
- void DFS(int x) {
- if(x == m) {
- for(int i=0;i<x;i++) printf("%d ", result[i]);
- printf("\n");
- }
- else {
- for(int i=1;i<=n;i++) {
- if(!check[i]) {
- result[x] = i;
- check[i] = true;
- DFS(x+1);
- check[i] = false;
- result[x] = 0;
- }
- }
- }
- }
- int main() {
- scanf("%d %d", &n, &m);
- DFS(0);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement