SPOJ PERMUT1

64. Permutations
http://www.spoj.pl/problems/PERMUT1/

Summary
Calculate the exact number of permutations containing the specified number of inversions.

Implementation
A brute force solution to this problem will exceed the allotted time limit. A better approach is to use dynamic programming to build a matrix containing all the possible solutions and then to simply look up the required numbers.

Input
The number of test cases is specified on the first line. Each test case consists of two numbers. The first 1 <= n <= 12 is the number of elements and the second 0 <= k <= 98 is the number of inversions to find.  1 4 1 

Output
 3 