标签:
2 3 1 4 2
1 2 3 12 13 14 21 23 24 31 32 34 41 42 43
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 using namespace std; 5 int dis[15], vis[15]; 6 int n, m; 7 void Dfs(int a) 8 { 9 if(a == m) 10 { 11 for(int i = 0; i < m; i++) 12 printf("%d", dis[i]); 13 printf("\n"); 14 return; 15 } 16 else 17 { 18 for(int j = 1; j <= n; j++) 19 { 20 if(vis[j]) 21 continue; 22 vis[j] = 1; 23 dis[a] = j; 24 Dfs(a + 1); 25 vis[j] = 0; 26 } 27 } 28 } 29 int main() 30 { 31 int t; 32 scanf("%d", &t); 33 while(t--) 34 { 35 memset(vis, 0, sizeof(vis)); 36 scanf("%d %d", &n, &m); 37 Dfs(0); 38 } 39 return 0; 40 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4722825.html