#abc226f. F - Score of Permutations

F - Score of Permutations

Score : 500500 points

问题描述

对于一个由 (1,2,,N)(1,2,\dots,N) 构成的排列 P=(p1,p2,,pN)P = (p_1, p_2, \dots, p_N),我们定义其得分 S(P)S(P) 如下:

  • NN 名编号为 1,2,,N1,2,\dots,N 的人,此外还有 Snuke。最初,编号为 ii (1iN)(1 \leq i \leq N) 的人持有第 ii 号球。 每当 Snuke 大喊时,所有满足 ipii \neq p_i 的编号为 ii 的人会同时将他们的球交给编号为 pip_i 的人。 如果在至少大喊一次之后,每个编号为 ii 的人都持有第 ii 号球,则 Snuke 停止大喊。 得分是指 Snuke 在停止大喊前所大喊的次数。这里保证得分将是一个有限值。

存在 N!N! 种由 (1,2,,N)(1,2,\dots,N) 构成的排列 PP。求这些排列中,每种排列的得分的 KK 次方之和,结果对 998244353998244353 取模。

  • 形式上,令 SNS_N 表示由 (1,2,,N)(1,2,\dots,N) 构成的排列集合。计算以下表达式:$\displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}$.

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

Problem Statement

For a permutation P=(p1,p2,,pN)P = (p_1, p_2, \dots, p_N) of (1,2,,N)(1,2, \dots, N), let us define the score S(P)S(P) of PP as follows.

  • There are NN people, numbered 1,2,,N1,2,\dots,N. Additionally, Snuke is there. Initially, Person ii (1iN)(1 \leq i \leq N) has Ball ii.
    Each time Snuke screams, every Person ii such that ipii \neq p_i gives their ball to Person pip_i simultaneously.
    If, after screaming at least once, every Person ii has Ball ii, Snuke stops screaming.
    The score is the number of times Snuke screams until he stops. Here, it is guaranteed that the score will be a finite value.

There are N!N! permutations PP of (1,2,,N)(1,2, \dots, N). Find the sum, modulo 998244353998244353, of the scores of those permutations, each raised to the KK-th power.

  • Formally, let SNS_N be the set of the permutations of (1,2,,N)(1,2, \dots, N). Compute the following: $\displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}$.

Constraints

  • 2N502 \leq N \leq 50
  • 1K1041 \leq K \leq 10^4
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN KK

Output

Print $\displaystyle \left(\sum_{P \in S_N} S(P)^K \right) \bmod {998244353}$.

Sample Input 1

2 2

Sample Output 1

5

When N=2N = 2, there are two possible permutations PP: (1,2),(2,1)(1,2),(2,1).

The score of the permutation (1,2)(1,2) is found as follows.

  • Initially, Person 11 has Ball 11, and Person 22 has Ball 22.
    After Snuke's first scream, Person 11 has Ball 11, and Person 22 has Ball 22.
    Here, every Person ii has Ball ii, so he stops screaming.
    Thus, the score is 11.

The score of the permutation (2,1)(2,1) is found as follows.

  • Initially, Person 11 has Ball 11, and Person 22 has Ball 22.
    After Snuke's first scream, Person 11 has Ball 22, and Person 22 has Ball 11.
    After Snuke's second scream, Person 11 has Ball 11, and Person 22 has Ball 22.
    Here, every Person ii has Ball ii, so he stops screaming.
    Thus, the score is 22.

Therefore, the answer in this case is 12+22=51^2 + 2^2 = 5.

Sample Input 2

3 3

Sample Output 2

79

All permutations and their scores are listed below.

  • (1,2,3)(1,2,3): The score is 11.
  • (1,3,2)(1,3,2): The score is 22.
  • (2,1,3)(2,1,3): The score is 22.
  • (2,3,1)(2,3,1): The score is 33.
  • (3,1,2)(3,1,2): The score is 33.
  • (3,2,1)(3,2,1): The score is 22.

Thus, we should print 13+23+23+33+33+23=791^3 + 2^3 + 2^3 + 3^3 + 3^3 + 2^3 = 79.

Sample Input 3

50 10000

Sample Output 3

77436607

update @ 2024/3/10 09:56:07