#P2915. Mixed Up Cows
Mixed Up Cows
Mixed Up Cows
Farmer John's cows each have a unique serial number. They wish to line up for milking in a "Mixed Up" order: an ordering of the cows such that for every pair of consecutive cows, the absolute difference of their serial numbers is greater than \(K\). Formally, if the ordering is \(S_{1}, S_{2}, \ldots, S_{N}\), then for all \(1 \le i K\).
You are given \(N\) and \(K\) along with the unique serial numbers \(S_{i}\) (with constraints \(4 \le N \le 16\), \(1 \le S_{i} \le 25000\), and \(1 \le K \le 3400\)). Your task is to count the number of different ways the cows can be arranged in a Mixed Up lineup.
inputFormat
The first line contains two integers \(N\) and \(K\). The following \(N\) lines each contain one integer \(S_{i}\) representing the serial number of a cow.
outputFormat
Output a single integer: the number of valid Mixed Up arrangements.
sample
4 1
1
3
5
7
24