#P2915. [USACO08NOV] Mixed Up Cows G

[USACO08NOV] Mixed Up Cows G

Problem Description

Each of Farmer John's NN (4≤N≤164 \le N \le 16) cows has a unique serial number SiS_i (1≤Si≤250001 \le S_i \le 25000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large letters on a gold plate hung around her ample bovine neck.

Gangsta cows are rebellious and line up to be milked in an order called 'Mixed Up'. A cow order is 'Mixed Up' if the sequence of serial numbers formed by their milking line is such that the serial numbers of every pair of consecutive cows in line differs by more than KK (1≤K≤34001 \le K \le 3400). For example, if N=6N = 6 and K=1K = 1 then 1,3,5,2,6,41, 3, 5, 2, 6, 4 is a 'Mixed Up' lineup but 1,3,6,5,2,41, 3, 6, 5, 2, 4 is not (since the consecutive numbers 55 and 66 differ by 11).

How many different ways can NN cows be Mixed Up?

For your first 1010 submissions, you will be provided with the results of running your program on a part of the actual test data.

POINTS: 200200.

Input Format

Line 11: Two space-separated integers: NN and KK.

Lines 2…N+12 \dots N+1: Line i+1i+1 contains a single integer that is the serial number of cow ii : SiS_i.

Output Format

Line 11: A single integer that is the number of ways that NN cows can be 'Mixed Up'. The answer is guaranteed to fit in a 64 bit integer.

4 1 
3 
4 
2 
1 

2 

Hint

The 22 possible Mixed Up arrangements are:

  • 3,1,4,23,1,4,2

  • 2,4,1,32,4,1,3