当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

7200:Yet Another Easy Permutation Count Problem

题目描述
Silver187 likes Permutation. For a permutation $P$ of length $n$, a position $x(2\le x\le n-1)$ is a good position if and only if $\forall 1\le i\le x-1$,$P_i\lt P_x$, and $P_x \gt P_{x+1}$. In particular:
1. position $1$ is a good position if and only if $P_1>P_2$ and $n\geq 2$.
2. position $n$ can never be a good position.

Silver187 wants to calculate the beauty value of a permutation $P$ of length $n$. He defines a number $S$, initially $S=0$. Silver187 will repeat the following operations for the permutation $P$ until the permutation $P$ is in ascending order.

1. Add to $S$ the number of good positions in the current permutaion $P$.

2. Do a bubble sort on the permutation $P$(For each $i$ from $1$ to $n - 1$ in order, if $P_i$ > $P_{i+1}$, swap $P_i$, $P_{i+1}$).

$S$ is the beautiful value of the permutation $P$.

Silver187 gives you two numbers $n$ and $m$. There are $m$ constraints. Every constraint will give $x$ and $y$, which means the inital number of position $x$ is $y$. Find the sum of the beauty values of all permutations that satisfy all constraints modulo $998244353$.
输入解释
The first line has one integer $T(1≤T≤100)$, indicating there are $T$ test cases.

In each case:

The first line contains two integers $n(1\le n\le 10^6)$, $m(0\le m\le n)$---the length of the permutation and the number of constraints.

The $i$-th line of the next $m$ line contains two integers---the $i$-th constraint.

It is guaranteed that there is at least one permutation that satisfies all constraints.

Input guarantee $1\le \sum m\le \sum n\le 10^7$.
输出解释
In each case, output a single integer---the sum of the beautiful values of all permutations that satisfy the constraints modulo $998244353$.
输入样例
2
3 1
1 2
7 5
4 5
2 2
6 7
3 3
1 4

输出样例
3
13

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-7200

最后修改于 2022-09-15T06:17:19+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
30000/15000MS(Java/Others) 524288/262144K(Java/Others)