这是用户在 2024-7-25 18:18 为 https://ac.nowcoder.com/acm/contest/82345/A 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
How Many Permutation?
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 262144K,其他语言524288K
64bit IO Format: %lld

题目描述

Given a sequence of length nn and a positive integer kk, you can permute the sequence. The goal is to permute the sequence in such a way that the difference between any two adjacent elements is at least kk. How many different permutations can achieve this goal? It is guaranteed that the nn elements in the sequence are all distinct.

输入描述:

The first line contains two integers n(1n8)n (1\leq n \leq 8) and k(1k20)k (1\leq k\leq 20), representing the length of the sequence and the difference value, respectively.
The second line contains nn integers a1,a2,...,an(1ai20)a_1, a_2, ..., a_n (1\leq a_i\leq 20), representing the elements in the sequence.

输出描述:

Output an integer in a single line, representing the number of permutations that achieve the goal.
示例1

输入

复制
3 2
1 2 4

输出

复制
2

说明

In the example, only permutaions [1,4,2][1, 4, 2] and [2,4,1][2, 4, 1] achieve the goal.
只看题目内容
ACM模式
运行结果自测输入