Introversion

시간 제한3초메모리 제한1024 MB

요약
2n개의 접시를 두 개씩 놓은 상태에서 일부가 채워져 있을 때, 같은 종류가 이웃하지 않도록 남은 접시를 배치하는 경우의 수를 10^9+7로 나눈 나머지를 구한다.
난이도

보통10점 중 6점

유형
동적 계획법, 조합론, 구현
정답자
아직 제출이 없습니다

문제

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 x_1,x_2,⋯ ,x_2nx\_1,x\_2, \cdots ,x\_{2n} separated by a space. If x_i=0x\_i=0 it means that the ii-th position on the table is empty. Otherwise, x_ix\_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,…,nk∈\\{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.

제한

  • 1≤T≤201≤T≤20
  • 2≤n≤1002≤n≤100
  • 0≤x_i≤n0≤x\_i≤n

예제1

  1. 예제 1

    입력
    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