Count ways to place fixed and shared numbers into two increasing rows so every column increases downward.
Medium6Dynamic programmingCombinatoricsNo attempts yetTime limit1sMemory limit256 MBYou are given a positive integer N. The integers 1,2,3,…,2N are split into three sets A, B and C. Count the number of ways to fill a table with two rows and N columns so that all of the following hold.
Every integer from 1 to 2N appears in the table exactly once.
For N=4, A={2,3}, B={4,7,8} and C={1,5,6}, exactly two tables satisfy the conditions.
1 2 3 5
4 6 7 8
1 2 3 6
4 5 7 8
The first line holds the integer N. (1<N≤35)
The second line holds M, the number of elements of set A, followed by the elements of A. (0≤M≤N)
The third line holds K, the number of elements of set B, followed by the elements of B. (0≤K≤N)
A and B are disjoint, and every element of both sets is an integer between 1 and 2N. The elements on a line are not necessarily sorted. The integers that belong to neither A nor B form set C.
Print the number of tables that satisfy the conditions on a single line. Print 0 if no such table exists.