#P15925. [TOPC 2023] Introversion

    ID: 29381 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2023容斥原理ICPC台湾

[TOPC 2023] Introversion

题目描述

You run a restaurant called Taste Of Pacific Cuisine (TOPC). This weekend, you will be hosting a large banquet that caters a sizable group of guests. Your chef designed nn types of dishes. To ensure every guest a chance to taste each type of the dishes, you plan to prepare two dishes per dish type. (Hence there are a total of 2n2n dishes at the banquet.)

There is a very long table in your restaurant, and you plan to exhibit all 2n2n dishes in a line on this table all at once. Not surprisingly, the length of the table fits exactly 2n2n dishes. As a considerate host, you plan to make sure that no two dishes of the same type are laying on the table together — this allows a variety of choices for introversion individuals who prefer not to wander around.

Now, some dishes have already been brought to the table. Can you quickly count the number of ways to place the remaining dishes such that no two dishes of the same type are placing together? You must compute this number quickly so you can give an introductory overview to your kitchen staff on how to place the remaining dishes — that’s what you call an intro version. Since the number of ways could be large, it suffices to output the answer modulo 109+710^9 + 7.

输入格式

The first line contains an integer TT, denoting the number of test cases. For each test case, the first line contains an integer nn. The second line contains 2n2n integers x1,x2,,x2nx_1, x_2, \cdots, x_{2n} separated by a space. If xi=0x_i = 0 it means that the ii-th position on the table is empty. Otherwise, xix_i will be an integer ranges between 11 and nn denoting the type of the dish. It is guaranteed that for each dish type k{1,2,,n}k \in \{1, 2, \dots, n\}, kk occurs at most twice in the input sequence. In addition, if kk does occur two times in the sequence, these two numbers will not be neighboring.

输出格式

Output the number of valid ways to serve all the remaining dishes, modulo 109+710^9 + 7.

3
2
1 2 0 0
2
1 0 2 0
5
0 0 0 0 0 1 2 3 4 5
1
0
96

提示

  • 1T201 \le T \le 20.
  • 2n1002 \le n \le 100.
  • 0xin0 \le x_i \le n.