luogu#P3311. [SDOI2014] 数数

    ID: 7341 Type: RemoteJudge 1000ms 500MiB Tried: 3 Accepted: 1 Difficulty: 8 Uploaded By: Tags>AC 自动机动态规划dp字符串2014山东数位 dpO2优化

[SDOI2014] 数数

Problem 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