From 1fcb62a69eab9a7d96ea62122efa5667b1306ea6 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 26 Feb 2008 12:05:01 +0100 Subject: [PATCH] More hatchecks. --- rank.tex | 69 +++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 61 insertions(+), 8 deletions(-) diff --git a/rank.tex b/rank.tex index 958e991..3d5386e 100644 --- a/rank.tex +++ b/rank.tex @@ -372,7 +372,7 @@ When we substitute~$x=0$ in the above equality, we get a~formula for the number of rook placements avoiding~$H$: $$N_0 = N(0) = \sum_{k=0}^n (-1)^k \cdot (n-k)! \cdot r_k.$$ -\example +\example\id{hatcheck}% Let us apply this theory to the hatcheck lady problem. The set~$H$ of holes is the main diagonal of the board: $H=\{ (i,i) : i\in[n] \}$. When we want to place $k$~rooks on the holes, we can do that in $r_k={n\choose k}$ ways. By the previous corollary, the number of @@ -570,10 +570,10 @@ complete bipartite with the matching $\{(i,i) : i\in[n]\}$ deleted. For a~given order~$n$, we will call this matrix~$D_n$ and the graph~$G_n$ and we will show that the submatrices of~$D_n$ share a~nice property: -\lemma +\lemma\id{submatrixlemma}% If $D$ is a~submatrix of~$D_n$ obtained by deletion of rows and columns. -Then the value of the permanent of~$D$ depends only on $n$ and the number of zero -entries in~$D$. +Then the value of the permanent of~$D$ depends only on the size of~$D$ +and the number of zero entries in it. \proof We know from Lemma~\ref{permchar} that the permanent counts matchings in the @@ -583,10 +583,63 @@ the number of matchings instead. As~$G_n$ is a~complete bipartite graph without edges of a~single matching, the graph~$G$ must be also complete bipartite with some non-touching edges -missing (but the number of such edges can be less than~$n$). Two such graphs -$G$ and~$G'$ are therefore isomorphic if and only if the number of missing -edges is the same. As the number of matchings is isomorphism invariant, -the lemma follows. +missing (but this matching is not necessarily perfect). Two such graphs +$G$ and~$G'$ are therefore isomorphic if and only if they have the same +number of vertices and also the same number of missing edges. +As the number of matchings is isomorphism invariant, the lemma follows. +\qed + +\defn +Let $n_0(z,d)$ be the permanent shared by all submatrices as described +by the above lemma, which have $d\times d$ entries and exactly~$z$ zeroes. + +\para +Instead of maintaining the matrix~$M$ in the algorithm, it is sufficient to keep +the number~$z$ of zeroes in the matrix and the set~$Z$ which contains the elements +$x\in A$ whose locations are restricted (there is a~zero anywhere in the $(R_A(x)+1)$-th +column of~$M$). In other words, every $x\in Z$ can appear at all positions in the +permutation except one (and these forbidden positions are different for different~$x$'s), +while the remaining elements of~$A$ can appear anywhere. + +As we already observed (\ref{hatcheck}) that the number of derangements on~$[n]$ is $\Theta(n!)$, +we can again use word-sized vectors to represent the sets~$A$ and~$Z$ with insertion, +deletion, ranking and unranking on them in constant time. + +The submatrix $M'=M^{1,k}$ for an~element $x$ of~rank~$k-1$ is described by either +$z'=z-1$ and~$Z'=Z\setminus\{x\}$ (if $x\in Z$) or $z'=z$ and $Z'=Z'$ (if $x\not\in Z$). +All computations of~$N_0$ in the algorithm can therefore be replaced by looking +up the appropriate $n_0(z',\vert A\vert-1)$ in a~precomputed table. Moreover, we can +calculate a~single~$C_a$ in constant time, because all summands are either $n_0(z,\vert A\vert-1)$ +or $n_0(z+1,\vert A\vert-1)$ depending on the set~$Z$. So we get: +$$C_a = r\cdot n_0(z+1,\vert A\vert-1) + (a-r) \cdot n_0(z,\vert A\vert-1),$$ +where $r=R_Z(R^{-1}_A(a))$, that is the number of restricted elements among the $a$~smallest ones in~$A$. + +It remains to show how to precompute the table of the $n_0$'s efficiently. + +\lemma +The function~$n_0$ satisfies the following recurrence: +$$\eqalign{ +n_0(0,d) &= d!, \cr +n_0(d,d) &= d! \cdot \sum\nolimits_{k=0}^d {(-1)^k \over k!}, \cr +\noalign{\medskip} +n_0(z,d) &= z\cdot n_0(z-1,d-1) + (d-z)\cdot n_0(z,d-1) \quad\hbox{for $z