Time Limit: 2000MS | Memory Limit: 65535KB |
Submissions: 435 | Accepted: 170 |
3
123 132 213 231 312 321
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 |
#include<iostream> #include <cstdio> using
namespace std; int
s[10]; int
s1[10]; int
vis[10] = {0}; void
dfs( int
l, int
n ) { int
i; if (l>=n) { for (i= 0;i<n;i++) printf ( "%d" ,s1[i]); printf ( "\n" ); } for (i=0;i<n;i++) { if (!vis[i]) { vis[i] = 1; s1[l] = s[i]; dfs(l+1,n); vis[i] = 0; } } } int
main() { int
num; cin>>num; for ( int
i=0;i<num;i++) s[i] = i+1; dfs (0, num); return
0; } |
原文:http://www.cnblogs.com/locojyw/p/3704851.html