You are on page 1of 2

Problem 5: Battle Formation

(100 points)

It’s time for the final battle and the Na’vi are preparing an army. After a
thorough inspection of the soldiers, Tsu’tey has given each soldier a value which
accounts for qualities like his strength, skills in battle, leadership skills etc.
However, thanks to the battleplan of the Na’vi, the soldiers have to be placed
in a particular order. Any deviation from this order would lead to total disaster.

The soldiers are divided into platoons. Platoons move in a straight line one after
the another. The total strength of a platoon is equal to the sum of the strengths
of the individual soldiers constituting the platoon. During the arrangement, if
a platoon X with higher strength than platoon Y is placed behind platoon
Y, then this is a mismatch. Tsu’tey and Jake Sully wish to keep track of the
number of such mismatches. Too many mismatches would lead to weakening of
the battle formation and eventual defeat. Since the number of mismatches is
dependent on the platoon strength, Jake and Tsu’sey wish to try out various
platoon sizes (their math is really weak, so all they can do is trial and error).
They have asked you to help them out. They will divide the army into platoons,
compute the strength of each platoon and ask you to find how many arrange-
ments of the platoons in a straight line would give atmost a certain number of
mismatches. Can you help them out? You may assume that no two platoons
have same strength.

Input format:

The first line contains the number of test cases (T).

For each test case:
a. The first line contains an integer N giving the number of platoons and an
integer k giving the maximum number of mismatches.
b. The next N lines have one integer per line, signifying the strength of the N

Output format:

For each test case, output one integer (modulo 1000) giving the number of
arrangements of the platoons in a straight line such that there are atmost k

Sample Input:

Sample Output: