#P10254. 口吃

    ID: 10948 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>动态规划 DP数学洛谷原创O2优化前缀和洛谷月赛

口吃

Background

There is a formal statement of the problem at the end of the description.

Problem Description

Because of practicing rap, ZHY has become a stutterer.

ZHY’s stutter is very special. Specifically, suppose ZHY wants to read a passage with nn characters. Then he will read the first character once, the second character twice, the third character three times, ... and the nn-th character nn times. For example, “原神启动” would be read by ZHY as “原神神启启启动动动动”.

YHZ has nn characters in hand. Each character has a pleasantness value aia_i set by YHZ, and a1na_{1\sim n} forms a permutation of 1n1\sim n. Now, he wants to rearrange these nn characters into a passage for ZHY to read. Since YHZ likes playing Genshin Impact (Yuánshén), he requires that after rearrangement, the number of inversions in the sequence aa is exactly kk. However, YHZ has not decided the order of the characters yet, so please compute, over all possible permutations, the sum of the total pleasantness values of all characters that YHZ will hear when ZHY reads the passage in order. Obviously, if YHZ hears a character multiple times, its pleasantness value should be counted multiple times in the total.

Formal statement

A permutation a1,a2,,ana_1,a_2,\cdots,a_n of 1n1\sim n is called valid if and only if its number of inversions is exactly kk. Also, for a permutation a1,a2,,ana_1,a_2,\cdots,a_n, its weight is i=1ni×ai\sum_{i=1}^n i\times a_i.

Given nn and kk, please compute the sum of weights of all valid permutations of 1n1\sim n, modulo 998244353998244353.

The number of inversions of a permutation is defined as i=1nj=i+1n[ai>aj]\sum_{i=1}^n\sum_{j=i+1}^n [a_i>a_j].

Input Format

One line with two integers n,kn,k.

Output Format

One line with one integer, the answer modulo 998244353998244353.

3 2
22
7 5
22066

Hint

Sample 11 explanation

There are only two valid permutations: 2 3 12\ 3\ 1 and 3 1 23\ 1\ 2. Their weights are both 1111, so the answer is 2222.


For 10%10\% of the testdata, n10n \le 10.

For 25%25\% of the testdata, n100n \le 100.

For another 20%20\% of the testdata, k300k \le 300.

For 100%100\% of the testdata, 1n3001 \le n \le 300, 0kn(n1)20\le k \le \frac{n(n-1)}{2}.

Translated by ChatGPT 5