AR2015PE - Queue of Soldiers
In a planet far away from Earth, there is a deadly war going on between two countries: Bitland and Byteland. The queen of Bitland has an army of N soldiers. She has found a strategy to attack the weakest part of the border of Byteland, but to reach there, the soldiers of Bitland has to form a queue and pass through a very narrow valley. Moreover, there is some defense mechanism set in the valley by Byteland: If any soldier P with height v passes through the valley, then anybody following P with height (strictly) greater than v will be killed by automatic firing.
The queen of Bitland is also aware of this scenario, but it is not always possible to send her soldiers according to the non-increasing order of heights (so that no soldier dies). She understands that some soldiers have to sacrifice their lives. To find the best possible permutation, she wants your help to calculate the number of different permutations of the heights of her soldiers so that exactly K soldiers die in that valley. A permutation is X different from another permutation Y if there exists some i (1 ≤ i ≤ N) for which the height of i-th soldier is different in these two permutations.
Input
The first line of input file contains the number of test cases, T (1 ≤ T ≤ 20). Then T cases follow: Each case consists of two lines. The first line contains two integers: N (1 ≤ N ≤ 50000) and K (0 ≤ K ≤ 1000). Then the second line contains N integers denoting the heights of the soldiers. There will be at most 100 different values of their heights. There will be at most 1000 soldiers with same height. For 80% of the cases, N will be less than 10000.
Output
For each case, print “Case <x>: <y>” in a separate line, where x is the case number and y is the number of permutations such that exactly K soldiers die. As the number can be very large, print y modulo 1000000007
Example
Input: 3 3 1 1 2 3 3 1 1 2 2 3 2 1 2 3 Output: Case 1: 3 Case 2: 1 Case 3: 2
hide comments
Lovro Puzar:
2017-12-30 15:50:31
To clarify, the oldest comment (dated 2016-07-10) is wrong. The example test case is correct. |
|
Rishav Goyal:
2016-08-12 11:10:30
will it pass (n*k) since 20%cases will be having large n? |
|
deepukps:
2016-07-10 15:37:23
I think the answers for case 2 and 3 have been swapped . Correct me if I am wrong . |
Added by: | Gầy :)) |
Date: | 2016-07-09 |
Time limit: | 1s-5s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All except: ASM64 GOSU JS-MONKEY |
Resource: | The 2015 ACM-ICPC Asia Phuket Regional Programming Contest |