8527: Easy Counting Problem

内存限制:256 MB 时间限制:8 S 标准输入输出
题目类型:传统 评测方式:Special Judge 上传者:
提交:1 通过:0

题目描述

Yukikaze is learning stringology. She found a series of interesting problems at the end of her textbook as follows.

We consider a string to be good if it satisfies the following conditions:
  •  It consists of decimal digits less than www.
  •  Digit iii appears at least cic_ici times.
We consider two strings to be different if they are different in length or there exists an integer iii such that the letters in their iii-th position are different.
The problem in the textbook asks for the number of different good strings of length nnn.

输入格式

The first line contains a single integer www (2≤w≤102 \leq w \leq 102w10), indicating that a good string consists of decimal digits less than www.
The second line contains www integers c0,c1,…,cw−1c_0,c_1,\ldots,c_{w-1}c0,c1,,cw1 (1≤ci≤500001 \leq c_i \leq 500001ci50000, c0+c1+…+cw−1≤50000c_0+c_1+\ldots+c_{w-1} \leq 50000c0+c1++cw150000), indicating that the decimal digit iii appears at least cic_ici times in a good string.
The third line contains a single integer qqq (1≤q≤3001 \leq q \leq 3001q300), indicating the number of queries.
Each of the next qqq lines contains a single integer nnn (1≤n≤1071 \leq n \leq 10^71n107), indicating the length of the string.

输出格式

For each query, output an integer in a single line indicating the number of different good strings of length nnn. As the answer may be large, please output the answer modulo 998244353.

输入样例 复制

2
1 1
3
3
5
7

输出样例 复制

6
30
126

数据范围与提示

If we set n=3n=3n=3, w=2w=2w=2, c0=c1=1c_0=c_1=1c0=c1=1, then the answer is 666, including 001,010,011,100,101,110\texttt{001}, \texttt{010}, \texttt{011}, \texttt{100}, \texttt{101}, \texttt{110}001,010,011,100,101,110.

分类标签