Find number of ways to create sequence A of length n satisfying m conditions. This sequence A should consist of only non negative numbers. Each condition is described by three i
Following user3386109's suggestion, decompose each input constraint max(A[i], A[j]) = k into three constraints:
We can count solutions using a DPLL-like backtracking procedure. First, the equivalent of unit propagation:
If all constraints are of the first two types, we can count the number of solutions by taking the product of (k + 1) for each k that is the right-hand side of a non-redundant inequality constraint.
Otherwise, there is a constraint A[i] = k ∨ A[j] = k. We make two recursive calls: one with the extra constraint A[i] = k and one with the extra constraint A[i] ≤ k - 1 (we know that A[i] > k is impossible).
The depth of the recursive tree is at most n, since each child call fixes more variables than its parent after unit propagation. Hence the search tree has O(2n) nodes, each of which should be decently cheap.