Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 1,095 Bytes
c623d8c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
In this problem you need to count number of possible permutations **p** of the
first **N** integers, given **N-1** constraints of the form **pi < pj.**

## Input

The first line contains an integer **T**, **T** ≤ 20, followed by **T** test
cases. Each test case begins with an integer **N**, **N** ≤ 1,000, which is
the number of integers in the permutation. The next **N - 1** lines each
contain a single constraint in the following format: "**i** **sign** **j**",
where 0 ≤ **i**, **j****N - 1** and **sign** is either "**<**" or "**>**",
which denotes whether the **i**-th element of the permutation should be less
than or greater than the **j**-th element.

It is guaranteed that it is not possible to partition indices into two
disjoint sets A and B such that there is no constraint involving elements from
both A and B.

## Output

For each test case, output one single line with the number of permutations
that satisfy all the constraints, following the output format shown in the
example. The answer may be very large, so you should give the result modulo
**1,000,000,007**.