标签:
5 3
543 542 541 532 531 521 432 431 421 321
1 #include <cmath> 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 using namespace std; 6 int dis[15], vis[15], m, n; 7 void Dfs(int a, int b) 8 { 9 if(b == n + 1) 10 { 11 for(int i = 1; i <= n; i++) 12 printf("%d", dis[i]); 13 printf("\n"); 14 return; 15 } 16 for(int i = a; i > 0; i--) //保证顺序; 17 { 18 if(vis[i]) 19 continue; 20 vis[i] = 1; 21 dis[b] = i; 22 Dfs(i-1, b+1); //递归; 23 vis[i] = 0; //回溯; 24 } 25 } 26 int main() 27 { 28 while(~scanf("%d %d", &m, &n)) 29 { 30 memset(vis, 0, sizeof(vis)); 31 Dfs(m, 1); //传参, “1” 为dis[]数组中以一位下标存第一个数: 32 } 33 return 0; 34 }
标签:
原文地址:http://www.cnblogs.com/fengshun/p/4705925.html