Count distinct lineups of soldiers with given heights where exactly K soldiers have a strictly shorter soldier ahead of them.
Hard8CombinatoricsDynamic programmingSortingNo attempts yetTime limit5sMemory limit256 MBOn a planet far from Earth, Bitland and Byteland are at war. The queen of Bitland commands N soldiers. She has found the weakest point on Byteland's border, but to reach it her soldiers must form a single line and walk through a narrow valley.
Byteland has installed a defense device in the valley. Once a soldier of height v passes through, every soldier behind that one whose height is strictly greater than v is shot down. Put another way, a soldier dies exactly when at least one soldier standing earlier in the line is strictly shorter. The soldier at the front always survives.
The queen knows this. She cannot always send her soldiers in non-increasing order of height so that nobody dies, so some soldiers have to die. To find the best line, she asks you to count the arrangements of her soldiers' heights in which exactly K soldiers die in the valley.
Arrangement X differs from arrangement Y if there is an index i (1≤i≤N) at which the height of the i-th soldier differs between them.
The first line contains the number of test cases T (1≤T≤20).
Each test case consists of two lines. The first line contains two integers N (1≤N≤50000) and K (0≤K≤1000). The second line contains the heights of the N soldiers, separated by spaces. Every height is a positive integer, at most 100 distinct height values appear, and at most 1000 soldiers share the same height.
For each test case, print one line in the form Case x: y, where x is the case number starting from 1 and y is the number of arrangements in which exactly K soldiers die. The value of y can be very large, so print it modulo 1000000007.