2523. Mixed Up Cows

单点时限: 2.0 sec

内存限制: 256 MB

Each of Farmer John’s N (4 <= N <= 16) cows has a unique serial number S_i (1 <= S_i <= 25,000). The cows are so proud of it that each one now wears her number in a gangsta manner engraved in large etters 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 K (1 <= K <= 3400). For example, if N = 6 and K = 1 then 1, 3, 5, 2, 6, 4 is a ‘Mixed Up’ lineup but 1, 3, 6, 5, 2, 4 is not (since the consecutive numbers 5 and 6 differ by 1).

How many different ways can N cows be Mixed Up?

输入格式

  • Line 1: Two space-separated integers: N and K

  • Lines 2..N+1: Line i+1 contains a single integer that is the serial

number of cow i: S_i

输出格式

  • Line 1: A single integer that is the number of ways that N cows can

be ‘Mixed Up’. The answer is guaranteed to fit in a 64 bit

integer.

样例

Input
4 1
3
4
2
1
Output
2
OUTPUT DETAILS:
The 2 possible Mixed Up arrangements are:
3 1 4 2
2 4 1 3

4 人解决,14 人已尝试。

4 份提交通过,共有 36 份提交。

8.8 EMB 奖励。

创建: 15 年,9 月前.

修改: 7 年,4 月前.

最后提交: 1 年,5 月前.

来源: USACO 2008 NOV

题目标签