编程介的小学生 2017-08-05 13:16 采纳率: 20.5%
浏览 778
已采纳

Not only STL

Problem Description
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).

Input
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 a1,a2,a3,…,an Process to the end of file.
1≤n≤2000
1≤k≤1012
1≤ai≤2000

Output
For each case, output the answer in a single line.

Sample Input
3 1
1 2 3
3 1
1 1 2

Sample Output
1 3 2
1 2 1

  • 写回答

2条回答 默认 最新

  • threenewbee 2017-08-07 15:34
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办