bdfz_2024_summer/day4/U287193/U287193.md
2024-08-06 08:31:25 +08:00

77 lines
1.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 冒泡
## 题目描述
对于一个 $1\sim n$ 的排列 $a$ 和一个数 $m$,定义 $f(a,m)$ 为恰好经过 $m$ 轮冒泡排序后变为 $a$ 的不同排列数量。
一轮冒泡排序的过程如下:从小到大依次考虑每个 $i \in [1,n)$,如果 $a[i]>a[i+1]$,那么就交换 $a[i]$ 和 $a[i+1]$。
给定 $n,m$ 和一个长度为 $n$ 的序列 $lim$。一个排列 $a$ 合法当且仅当 $\forall i$,如果 $lim[i]\ne 0$,那么 $a[i] = lim[i]$。
你需要求出所有合法的 $a$ 的 $f(a,m)$ 之和。答案对 $998244353$ 取模。
## 输入格式
第一行,共两个数,表示 $n,m$。
第二行,共 $n$ 个数,表示 $lim[1...n]$。
## 输出格式
共一行,一个数,表示答案。
## 样例 #1
### 样例输入 #1
```
6 2
0 0 0 0 0 0
```
### 样例输出 #1
```
720
```
## 样例 #2
### 样例输入 #2
```
6 0
6 0 1 4 0 0
```
### 样例输出 #2
```
6
```
## 样例 #3
### 样例输入 #3
```
见下发样例
```
### 样例输出 #3
```
```
## 提示
对于 100% 的数据,$1\le n\le 5000, 0\le m\le n, 0\le lim[i]\le n$,保证 $lim[i]$ 互不相同。
子任务110pts$n\le 8$
子任务240pts所有 $lim[i]\ne 0$
子任务320pts$n\le 100$
子任务430pts无特殊限制