#P7967. [COCI 2021/2022 #2] Magneti

[COCI 2021/2022 #2] Magneti

Problem Description

You are given nn magnets and ll empty slots. The distance between adjacent slots is 11, and each slot can hold one magnet. All nn magnets must be placed. Each magnet can attract other magnets whose distance is less than rir_i.

Find the total number of ways to place the magnets so that no two magnets attract each other, modulo 109+710^9+7.

Input Format

The first line contains two positive integers n,ln, l, representing the number of magnets and the number of slots.

The second line contains nn integers rir_i.

Output Format

Output the total number of valid ways modulo 109+710^9+7.

1 10
10
10
4 4
1 1 1 1
24
3 4
1 2 1
4

Hint

Sample 2 Explanation: All permutations of the four magnets satisfy the requirements.

Sample 3 Explanation:

Use 1,2,3\texttt{1,2,3} to represent magnets, and _\texttt \_ to represent an empty slot. Then all valid arrangements are: 13_2\texttt{13\_2}, 31_2\texttt{31\_2}, 2_13\texttt{2\_13}, and 2_31\texttt{2\_31}.

Constraints

This problem uses bundled subtasks.

  • Subtask 1 (10 pts): r1=r2==rnr_1=r_2=\cdots=r_n.
  • Subtask 2 (20 pts): 1n101 \le n \le 10.
  • Subtask 3 (30 pts): 1n301 \le n \le 30, nl300n \le l \le 300.
  • Subtask 4 (50 pts): No special restrictions.

For 100%100\% of the testdata, 1n501 \le n \le 50, nl10000n \le l \le 10000, 1ril1 \le r_i \le l.

Hints and Notes

Translated from COCI 2021-2022 CONTEST #2 Task 4 Magneti.

The score settings follow the original COCI problem, with a full score of 110110.

Translated by ChatGPT 5