#abc267g. G - Increasing K Times

G - Increasing K Times

Score : 600600 points

问题描述

给定一个长度为 NN 的整数序列 A=(A1,,AN)A = (A_1, \dots, A_N)

求满足以下条件的置换 P=(P1,,PN)P = (P_1, \dots, P_N) 的个数,模 998244353998244353

  • 存在恰好 KK 个整数 ii,满足 1i(N1)1 \leq i \leq (N-1)(包含两端点),且有 APi<APi+1A_{P_i} < A_{P_{i + 1}}

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

You are given an integer sequence A=(A1,,AN)A = (A_1, \dots, A_N) of length NN.

Find the number, modulo 998244353998244353, of permutations P=(P1,,PN)P = (P_1, \dots, P_N) of (1,2,,N)(1, 2, \dots, N) such that:

  • there exist exactly KK integers ii between 11 and (N1)(N-1) (inclusive) such that APi<APi+1A_{P_i} \lt A_{P_{i + 1}}.

Constraints

  • 2N50002 \leq N \leq 5000
  • 0KN10 \leq K \leq N - 1
  • 1AiN(1iN)1 \leq A_i \leq N \, (1 \leq i \leq N)
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

A1A_1 \ldots ANA_N

Output

Print the answer.

Sample Input 1

4 2
1 1 2 2

Sample Output 1

4

Four permutations satisfy the condition: $P = (1, 3, 2, 4), (1, 4, 2, 3), (2, 3, 1, 4), (2, 4, 1, 3)$.

Sample Input 2

10 3
3 1 4 1 5 9 2 6 5 3

Sample Output 2

697112

update @ 2024/3/10 11:17:17