|
<p>In this problem you need to count number of possible permutations <strong>p</strong> of the first <strong>N</strong> integers, |
|
given <strong>N-1</strong> constraints of the form <strong>p<sub>i</sub> < p<sub>j</sub>.</strong><p> |
|
|
|
<h2>Input</h2> |
|
<p>The first line contains an integer <strong>T</strong>, <strong>T</strong> ≤ 20, followed by <b>T</b> test cases. Each test case begins with an integer <strong>N</strong>, <strong>N</strong> ≤ 1,000, which is the number of integers in the permutation. The next <strong>N - 1</strong> lines each contain a single constraint in the following format: "<b>i</b> <b>sign</b> <b>j</b>", where 0 ≤ <strong>i</strong>, <strong>j</strong> ≤ <strong>N - 1</strong> and <strong>sign</strong> is either "<strong><</strong>" or "<strong>></strong>", which denotes whether the <b>i</b>-th element of the permutation should be less than or greater than the <b>j</b>-th element.</p> |
|
|
|
<p>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.</p> |
|
|
|
<h2>Output</h2> |
|
<p>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 <strong>1,000,000,007</strong>.</p> |
|
|