#P3311. [SDOI2014] 数数

    ID: 2360 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>字符串动态规划,dp2014山东O2优化数位 dpAC 自动机

[SDOI2014] 数数

Description

We call a positive integer xx a lucky number if and only if its decimal representation does not contain any element from the set ss as a substring. For example, when s={22,333,0233}s = \{22, 333, 0233\}, 233233 is a lucky number, while 23332333, 2023320233, and 32233223 are not. Given nn and ss, compute the number of lucky numbers not greater than nn.

The answer is taken modulo 109+710^9 + 7.

Input Format

The first line contains an integer nn.

The second line contains an integer mm, the number of elements in ss.

The next mm lines each contain a digit string sis_i, representing an element of ss.

Output Format

Output a single line containing one integer, the answer modulo 109+710^9 + 7.

20
3
2
3
14
14

Hint

Sample 1 Explanation

Except for 3,13,2,12,20,143, 13, 2, 12, 20, 14, all integers not exceeding 2020 are lucky numbers.

Constraints

For all testdata, it is guaranteed that:

1n<1012011 \leq n < 10^{1201}, 1m1001 \leq m \leq 100, 1i=1msi15001 \leq \sum_{i = 1}^m |s_i| \leq 1500, mini=1msi1\min_{i = 1}^m |s_i| \geq 1, where si|s_i| denotes the length of string sis_i. nn has no leading 00, but sis_i may have leading 00.

Translated by ChatGPT 5