201142: [AtCoder]ARC114 C - Sequence Scores

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $600$ points

Problem Statement

For a sequence $A$ of length $N$ consisting of integers between $1$ and $M$ (inclusive), let us define $f(A)$ as follows:

  • We have a sequence $X$ of length $N$, where every element is initially $0$. $f(A)$ is the minimum number of operations required to make $X$ equal $A$ by repeating the following operation:
    • Specify $1 \leq l \leq r \leq N$ and $1 \leq v \leq M$, then replace $X_i$ with $\max(X_i, v)$ for each $l \leq i \leq r$.

Find the sum, modulo $998244353$, of $f(A)$ over all $M^N$ sequences that can be $A$.

Constraints

  • $1 \leq N, M \leq 5000$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$N$ $M$

Output

Print the sum of $f(A)$ over all sequences $A$, modulo $998244353$.


Sample Input 1

2 3

Sample Output 1

15

The $3 ^ 2 = 9$ sequences and the value of $f$ for those are as follows:

  • For $A = (1, 1)$, we can make $X$ equal it with one operation with $(l = 1, r = 2, v = 1)$, so $f(A) = 1$.
  • For $A = (1, 2)$, we can make $X$ equal it with two operations with $(l = 1, r = 2, v = 1)$ and $(l = 2, r = 2, v = 2)$, so $f(A) = 2$.
  • For $A = (1, 3)$, we can make $X$ equal it with two operations with $(l = 1, r = 2, v = 1)$ and $(l = 2, r = 2, v = 3)$, so $f(A) = 2$.
  • For $A = (2, 1)$, we can make $X$ equal it with two operations with $(l = 1, r = 2, v = 1)$ and $(l = 1, r = 1, v = 2)$, so $f(A) = 2$.
  • For $A = (2, 2)$, we can make $X$ equal it with one operation with $(l = 1, r = 2, v = 2)$, so $f(A) = 1$.
  • For $A = (2, 3)$, we can make $X$ equal it with two operations with $(l = 1, r = 2, v = 2)$ , $(l = 2, r = 2, v = 3)$, so $f(A) = 2$.
  • For $A = (3, 1)$, we can make $X$ equal it with two operations with $(l = 1, r = 2, v = 1)$ and $(l = 1, r = 1, v = 3)$ so $f(A) = 2$.
  • For $A = (3, 2)$, we can make $X$ equal it with two operations with $(l = 1, r = 2, v = 2)$ and $(l = 1, r = 1, v = 3)$, so $f(A) = 2$.
  • For $A = (3, 3)$, we can make $X$ equal it with one operation with $(l = 1, r = 2, v = 3)$, so $f(A) = 1$.

The sum of these values is $3 \times 1 + 6 \times 2 = 15$.


Sample Input 2

3 2

Sample Output 2

15

Sample Input 3

34 56

Sample Output 3

649717324

Input

题意翻译

给定一个由 $1 - M$ 的整数组成的,长为 $N$ 的序列 $A$。 对于 $A$ 定义 $f(A)$: - 给一个长为 $N$ 的序列 $X$,初始所有元素都为$0$,$f(A)$ 为: 重复以下操作,以使 $X$ 等于 $A$ 的最小操作次数。 - 指定 $1 \leq l \leq r \leq N$ 和 $1 \leq v \leq M$。 对于 $l \leq i \leq r$,将 $x_i$ 替换为 $max(x_i, v)$ 。 $A$ 共有 $M^N$ 个可能的序列。 求所有可得序列的 $f(A)$ 之和除以$9982444353$的余数。 输入:两个数 $N$ , $M$。 输出:一个数,为结果。 数据范围: $1 \leq N,M \leq 5000$

加入题单

上一题 下一题 算法标签: