歡迎您來到Tanky Woo的博客:
我們的【C++奮斗樂園】
C++/算法網站:www.cpply.com
C++/算法論壇:www.cppleyuan.com
QQ群:①群:19333724 ②群:23840480 ③群:17314377 ④群:23829384
題目地址:
http://poj.grids.cn/problem/1833/
此題有兩種方法:
方法一:利用STL里的next_permutation()函數,當然,這樣題就水了。
方法二:模擬,找出數列變化的特點。排列過程待補。。。大家記得提醒我。
直接發代碼了。
方法一:(STL)
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
// Grid 1833
// Author: Tanky Woo
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 1034
int ans[MAX];
// www.wutianqi.com
int main()
{
int nCases;
int num, k, i, j;
scanf("%d", &nCases);
while(nCases--)
{
scanf("%d %d", &num, &k);
for(i = 1; i <= num; ++i)
scanf("%d", &ans[i]);
for(i = 0; i < k; ++i)
next_permutation(ans+1, ans+num+1);
for(j = 1; j <= num; ++j)
printf("%d ", ans[j]);
printf("\n");
}
return 0;
}
方法二:(模擬)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// Grid 1833
// Author: Tanky [...]
文章來源:
http://www.wutianqi.com/?p=298
posted on 2010-07-09 20:45
Tanky Woo 閱讀(200)
評論(0) 編輯 收藏 引用