比如10以内,一行排2个,那么就有:
排列方式: 45
1 1,2
2 1,3
3 1,4
4 1,5
5 1,6
6 1,7
7 1,8
8 1,9
9 1,10
10 2,3
11 2,4
12 2,5
13 2,6
14 2,7
15 2,8
16 2,9
17 2,10
18 3,4
19 3,5
20 3,6
21 3,7
22 3,8
23 3,9
24 3,10
25 4,5
26 4,6
27 4,7
28 4,8
29 4,9
30 4,10
31 5,6
32 5,7
33 5,8
34 5,9
35 5,10
36 6,7
37 6,8
38 6,9
39 6,10
40 7,8
41 7,9
42 7,10
43 8,9
44 8,10
45 9,10
排7个,就有:
排列方式: 120
1 1,2,3,4,5,6,7
2 1,2,3,4,5,6,8
3 1,2,3,4,5,6,9
4 1,2,3,4,5,6,10
5 1,2,3,4,5,7,8
6 1,2,3,4,5,7,9
7 1,2,3,4,5,7,10
8 1,2,3,4,5,8,9
9 1,2,3,4,5,8,10
10 1,2,3,4,5,9,10
11 1,2,3,4,6,7,8
12 1,2,3,4,6,7,9
13 1,2,3,4,6,7,10
14 1,2,3,4,6,8,9
15 1,2,3,4,6,8,10
16 1,2,3,4,6,9,10
17 1,2,3,4,7,8,9
18 1,2,3,4,7,8,10
19 1,2,3,4,7,9,10
20 1,2,3,4,8,9,10
21 1,2,3,5,6,7,8
22 1,2,3,5,6,7,9
23 1,2,3,5,6,7,10
24 1,2,3,5,6,8,9
25 1,2,3,5,6,8,10
26 1,2,3,5,6,9,10
27 1,2,3,5,7,8,9
28 1,2,3,5,7,8,10
29 1,2,3,5,7,9,10
30 1,2,3,5,8,9,10
31 1,2,3,6,7,8,9
32 1,2,3,6,7,8,10
33 1,2,3,6,7,9,10
34 1,2,3,6,8,9,10
35 1,2,3,7,8,9,10
36 1,2,4,5,6,7,8
37 1,2,4,5,6,7,9
38 1,2,4,5,6,7,10
39 1,2,4,5,6,8,9
40 1,2,4,5,6,8,10
41 1,2,4,5,6,9,10
42 1,2,4,5,7,8,9
43 1,2,4,5,7,8,10
44 1,2,4,5,7,9,10
45 1,2,4,5,8,9,10
46 1,2,4,6,7,8,9
47 1,2,4,6,7,8,10
48 1,2,4,6,7,9,10
49 1,2,4,6,8,9,10
50 1,2,4,7,8,9,10
51 1,2,5,6,7,8,9
52 1,2,5,6,7,8,10
53 1,2,5,6,7,9,10
54 1,2,5,6,8,9,10
55 1,2,5,7,8,9,10
56 1,2,6,7,8,9,10
57 1,3,4,5,6,7,8
58 1,3,4,5,6,7,9
59 1,3,4,5,6,7,10
60 1,3,4,5,6,8,9
61 1,3,4,5,6,8,10
62 1,3,4,5,6,9,10
63 1,3,4,5,7,8,9
64 1,3,4,5,7,8,10
65 1,3,4,5,7,9,10
66 1,3,4,5,8,9,10
67 1,3,4,6,7,8,9
68 1,3,4,6,7,8,10
69 1,3,4,6,7,9,10
70 1,3,4,6,8,9,10
71 1,3,4,7,8,9,10
72 1,3,5,6,7,8,9
73 1,3,5,6,7,8,10
74 1,3,5,6,7,9,10
75 1,3,5,6,8,9,10
76 1,3,5,7,8,9,10
77 1,3,6,7,8,9,10
78 1,4,5,6,7,8,9
79 1,4,5,6,7,8,10
80 1,4,5,6,7,9,10
81 1,4,5,6,8,9,10
82 1,4,5,7,8,9,10
83 1,4,6,7,8,9,10
84 1,5,6,7,8,9,10
85 2,3,4,5,6,7,8
86 2,3,4,5,6,7,9
87 2,3,4,5,6,7,10
88 2,3,4,5,6,8,9
89 2,3,4,5,6,8,10
90 2,3,4,5,6,9,10
91 2,3,4,5,7,8,9
92 2,3,4,5,7,8,10
93 2,3,4,5,7,9,10
94 2,3,4,5,8,9,10
95 2,3,4,6,7,8,9
96 2,3,4,6,7,8,10
97 2,3,4,6,7,9,10
98 2,3,4,6,8,9,10
99 2,3,4,7,8,9,10
100 2,3,5,6,7,8,9
101 2,3,5,6,7,8,10
102 2,3,5,6,7,9,10
103 2,3,5,6,8,9,10
104 2,3,5,7,8,9,10
105 2,3,6,7,8,9,10
106 2,4,5,6,7,8,9
107 2,4,5,6,7,8,10
108 2,4,5,6,7,9,10
109 2,4,5,6,8,9,10
110 2,4,5,7,8,9,10
111 2,4,6,7,8,9,10
112 2,5,6,7,8,9,10
113 3,4,5,6,7,8,9
114 3,4,5,6,7,8,10
115 3,4,5,6,7,9,10
116 3,4,5,6,8,9,10
117 3,4,5,7,8,9,10
118 3,4,6,7,8,9,10
119 3,5,6,7,8,9,10
120 4,5,6,7,8,9,10
.net c#算法公式为:
public List<string> Arrange(int n, int r)
{
List<string> list = new List<string>();
int i = 0, j;
string s;
int[] a = new int[n];
a[i] = 1;
while (true)
{
if ((a[i] - i) <= (n - r + 1))
{
if (i == (r - 1))
{
s = "";
for (j = 0; j < r; j++)
{
s = s + (!string.IsNullOrWhiteSpace(s) ? "," : "")+ Convert.ToString(a[j]);
}
list.Add(s);
a[i] = a[i] + 1;
continue;
}
i = i + 1;
a[i] = a[i - 1] + 1;
}
else
{
if (i == 0)
{
return list;
}
i = i - 1;
a[i] = a[i] + 1;
}
}
}
效果如下: