Submit | All submissions | Best solutions | Back to list |
PERMUT1 - Permutations |
Let A = [a1, a2, ... an] be a permutation of integers 1, 2, ... n. A pair of indices (i, j), 1 <= i <= j <= n, is an inversion of the permutation A if ai > aj. We are given integers n > 0 and k >= 0. What is the number of n-element permutations containing exactly k inversions?
For instance, the number of 4-element permutations with exactly 1 inversion equals 3.
Task
Write a program which for each data set from a sequence of several data sets:
- reads integers n and k from input,
- computes the number of n-element permutations with exactly k inversions,
- writes the result to output.
Input
The first line of the input file contains one integer d, 1 <= d <= 10, which is the number of data sets. The data sets follow. Each data set occupies one line of the input file and contains two integers n (1 <= n <= 12) and k (0 <= k <= 98) separated by a single space.
Output
The i-th line of the output file should contain one integer - the number of n-element permutations with exactly k inversions.
Example
Input: 1 4 1 Output: 3
Added by: | adrian |
Date: | 2004-06-22 |
Time limit: | 3s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |
Resource: | III Polish Collegiate Team Programming Contest (AMPPZ), 1998 |
hide comments
|
|||||||
2013-08-10 07:02:13 shubham gupta
can anyone please explain why p<n*(n+1)/2 it should be p<(n)*(n-1)/2 for example if n=3 maximum inversions would be 2 [3 2 1]. correct me if i am wrong... |
|||||||
2012-09-29 22:18:13 Aayush Bahuguna
A simple dp problem :) |
|||||||
2012-07-20 08:46:01 npsabari
DP makes it look easy! |
|||||||
2012-03-16 03:21:42 sudhanshu barthwal
can anyone please post some test cases.. |
|||||||
2011-12-24 10:11:27 Prakhar Jain
nice one.....:) |
|||||||
2011-07-20 20:04:09 Gaston Ingaramo
Hey ~neo~ the inversions are 2,1,3,4 1,3,2,4 and 1,2,4,3 |
|||||||
2011-07-19 09:59:19 ~neo~
can anyone explain above test case.?? |
|||||||
2011-01-16 07:26:04 Nanda Bagus Pradnyana
cant anyone let me show any test case? |