QOJ.ac

QOJ

時間限制: 1 s 記憶體限制: 512 MB 總分: 100 可 Hack ✓

#2506. Sequence

统计

Given integers $n, m, k$, and an array of positive integers $v_0, v_1, \dots, v_m$ of length $m+1$.

For a non-negative integer sequence $\{a_i\}$ of length $n$ with 1-based indexing, where each element satisfies $0 \le a_i \le m$, we define its weight as $v_{a_1} \times v_{a_2} \times \dots \times v_{a_n}$.

A sequence $\{a_i\}$ is considered a valid sequence if the number of $1$s in the binary representation of the integer $S = 2^{a_1} + 2^{a_2} + \dots + 2^{a_n}$ is at most $k$.

Calculate the sum of weights of all valid sequences $\{a_i\}$, modulo $998244353$.

Input

The first line contains three integers $n, m, k$.

The second line contains $m+1$ integers, $v_0, v_1, \dots, v_m$.

Output

Output a single integer representing the sum of weights of all valid sequences, modulo $998244353$.

Examples

Input 1

5 1 1
2 1

Output 1

40

Note 1

Since $k = 1$, and knowing $n \le S \le n \times 2^m$, we have $5 \le S \le 10$. There is only one possible value for $S$: $S = 8$. This requires $a$ to contain two $0$s and three $1$s. Thus, there are $\binom{5}{2} = 10$ possible sequences. Each sequence contributes $v_0^2 v_1^3 = 4$, so the total weight sum is $10 \times 4 = 40$.

Input 2

See sequence/sequence2.in in the contestant directory.

Output 2

See sequence/sequence2.ans in the contestant directory.

Constraints

For all test cases, it is guaranteed that $1 \le k \le n \le 30$, $0 \le m \le 100$, and $1 \le v_i < 998244353$.

Test Case $n$ $k$ $m$
$1 \sim 4$ $= 8$ $\le n$ $= 9$
$5 \sim 7$ $= 30$ $\le n$ $= 7$
$8 \sim 10$ $= 30$ $\le n$ $= 12$
$11 \sim 13$ $= 30$ $= 1$ $= 100$
$14 \sim 15$ $= 5$ $\le n$ $= 50$
$16$ $= 15$ $\le n$ $= 100$
$17 \sim 18$ $= 30$ $\le n$ $= 30$
$19 \sim 20$ $= 30$ $\le n$ $= 100$

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.