Permutation (树状数组)

该博客介绍了一个利用树状数组解决寻找特定位置全排列的问题。输入包含测试用例数T和每组的整数K及序列S1,S2,...,Sk,通过特定公式计算出N并找到第N个按字典序排列的K个整数。思路是根据树状数组,逐位找出剩余元素中第Si+1大的数作为当前位的数值。提供的样例展示了不同输入下的正确输出。" 86036353,8256657,Delphi中UDP协议实现详解,"['网络编程', 'Delphi开发', 'UDP']
摘要由CSDN通过智能技术生成

Given N and K find the N-th permutation of the integers from 1 to K when those permutations are
lexicographically ordered. N starts from 0. Since N is very large N will be represented by a sequence
of K non-negative integers S1, S2, . . . , Sk. From this sequence of integers N can be calculated with
the following expression.

Input
First line of the input contains T (≤ 10) the number of test cases. Each of these test cases consists of
2 lines. First line contains a integer K (1 ≤ K ≤ 50000). Next line contains K integers S1, S2, . . . , Sk.
(0 ≤ Si ≤ K − i).
Output
For each test case output contains N-th permutation of the integers from 1 to K. These K integers
should be separated by a single space.
Sample Input
4
3
2 1 0
3
1 0 0
4
2 1 1 0
4
1 2 1 0
Sample Output
3 2 1
2

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值