We study a family of sorting match puzzles on grids, which we call permutation match puzzles. In this puzzle, each row and column of a $n \times n$ grid is labeled with an ordering constraint -- ascending (A) or descending (D) -- and the goal is to fill the grid with the numbers 1 through $n^2$ such that each row and column respects its constraint. We provide a complete characterization of solvable puzzles: a puzzle admits a solution if and only if its associated constraint graph is acyclic, which translates to a simple "at most one switch" condition on the A/D labels. When solutions exist, we show that their count is given by a hook length formula. For unsolvable puzzles, we present an $O(n)$ algorithm to compute the minimum number of label flips required to reach a solvable configuration. Finally, we consider a generalization where rows and columns may specify arbitrary permutations rather than simple orderings, and establish that finding minimal repairs in this setting is NP-complete by a reduction from feedback arc set.
翻译:我们研究一类在网格上的排序匹配谜题,称之为排列匹配谜题。在该谜题中,$n \times n$ 网格的每一行和每一列均标有排序约束——递增(A)或递减(D)——目标是用数字1至$n^2$填充网格,使得每一行和每一列均满足其约束。我们给出了可解谜题的完整刻画:一个谜题存在解当且仅当其关联约束图是无环的,这等价于A/D标签满足简单的“至多一次切换”条件。当解存在时,我们证明其数量可由钩长公式给出。对于不可解谜题,我们提出一种$O(n)$算法来计算达到可解配置所需的最小标签翻转次数。最后,我们考虑一种推广情形,其中行和列可指定任意排列而非简单排序,并通过反馈弧集的归约证明在此设定下寻找最小修复方案是NP完全的。