luogu#P6453. [COCI 2008/2009 #4] PERIODNI

    ID: 5469 远端评测题 5000ms 32MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP2008背包 DPCOCI(克罗地亚)笛卡尔树

[COCI 2008/2009 #4] PERIODNI

Problem Description

As shown in the figure, you are given a grid consisting of nn columns, and the bottoms of all columns are aligned.

You need to place kk identical numbers into it, but no two numbers may be in the same row or the same column.

For example, in the figure, placing b is invalid because the two b are in the same column. However, placing a is valid, because although the two a are on the same row, there is a gap between them, so it is not considered invalid.

Compute the total number of valid placements modulo 109+710^9+7.

Input Format

The first line contains two integers n,kn, k, representing the number of columns in the grid and the number of identical numbers to place.

The second line contains nn integers. The ii-th integer (from left to right) represents the height (number of levels) of the ii-th column.

Output Format

Output one integer on a single line, representing the number of valid placements modulo 109+710^9+7.

3 3
2 1 3
2
4 1
1 2 3 4
10
5 2
2 3 1 2 4
43
3 2
999999 999999 999999
990979013

Hint

Constraints

  • For 40%40\% of the testdata, the input numbers are all less than 1515.
  • For 70%70\% of the testdata, the input numbers are all less than 100100.
  • For 100%100\% of the testdata, 1n,k5001 \le n, k \le 500, and the column heights do not exceed 10610^6.

Notes

This problem is translated from COCI2008-2009 CONTEST #4 T6 PERIODNI

Input Format

The first line contains two integers n,kn, k, representing the number of columns in the grid and the number of identical numbers to place.

The second line contains nn integers. The ii-th integer (from left to right) represents the height (number of levels) of the ii-th column.

Output Format

Output one integer on a single line, representing the number of valid placements modulo 109+710^9+7.

Hint

Constraints

  • For 40%40\% of the testdata, the input numbers are all less than 1515.
  • For 70%70\% of the testdata, the input numbers are all less than 100100.
  • For 100%100\% of the testdata, 1n,k5001 \le n, k \le 500, and the column heights do not exceed 10610^6.

Notes

This problem is translated from COCI2008-2009 CONTEST #4 T6 PERIODNI

Translated by ChatGPT 5