当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5061:Not only STL

题目描述
As you know in STL there is a function called next_permutation, when you send a array to it, it will Rearranges the elements in the array into the next lexicographically greater permutation.

But today we need a next_k_permutation, you may say we can just apply k times next_permutation function to the array. Yes, you are right, but when k is very large it is not efficient enough.

So you are expected to write a program when given an array and k to find its next_k_permutation.
Note the next permutation of the permutation with largest dictionary order is the permutation with the minimum dictionary order. For example next permutation of (3,2,1) is (1,2,3).
输入解释
Multi test cases(about 1000). Each case contains two lines. The first line contains two integers n which indicates the length of the permutation and k. The second line contains n integers $a_1, a_2, a_3, \ldots, a_n$ Process to the end of file.
$1 \leq n \leq 2000$
$1 \leq k \leq 10^{12}$
$1 \leq a_i \leq 2000$
输出解释
For each case, output the answer in a single line.
输入样例
3 1
1 2 3
3 1
1 1 2
输出样例
1 3 2
1 2 1
来自杭电HDUOJ的附加信息
Recommend heyang

该题目是Virtual Judge题目,来自 杭电HDUOJ

题目来源 BestCoder Round #12

源链接: HDU-5061

最后修改于 2020-10-25T23:19:22+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
6000/1000MS(Java/Others) 32768/32768K(Java/Others)