二者間図の枝の最大化問題

最近トップコーダーのアルゴリズム問題を解こうとしています。 三角を合わせる問題で、上と下の三角の重線と高さを前提として組の数を数える事が目的です。上の三角の重線が下の三角の重線より短い事が必要です。This bipartite maximization problem is accomplished via a recursive correction algorithm whereby an initial assignment is made between the left and right sides of the graph and then a loop is run over all top triangles. For each top triangle, the algorithm tries to assign it to a bottom triangle without displacing any others (each top can be assigned to at most one bottom triangle). Thus, the change is at worst preserving the total number of triangle pairs and at best adding one to the total (if this top had been unassigned). The complexity appears to be O(|T||B||T|) or O(N^3), if T and B have the same maximal size.
回帰の基礎は以下のコード
if(seenLeft[topNode]) return false
Basically, if a top node has already been assigned to a bottom node in this recursion tree, then that bottom node cannot be considered for another top node and a recursive call cannot be made a second time for this top node. Note that such a top node might have been seen at a lower level in the tree to the left of the current top node, as the recursion is depth first. Update - this base case actually can never occur. If the top node was assigned already in this recursive subtree, this would mean that the bottom node was already marked as taken in this recursion (else the recursive call would not have occurred). The number of top nodes considered in all recursive calls that return true is bound at O(|T|), due to the fact that no top node is visited twice in a tree. For each true recursive call, there are at most O(|B|) false recursive calls. A key fact is that the nth top node can be mstched with a bottom node only invrecursive trees rooted at node n or higher.