【CodeForces - 585F】Digits of Number Pi

这篇博客探讨了一个关于圆周率π的假设,即任何数字序列都可以在π的无限小数部分找到。Vasily设计了一个算法,通过定义‘半出现’字符串的概念,来检查给定数字区间内有多少数在π的数字串中半出现。博主通过数位DP和AC自动机的方法实现了算法,并提供了代码实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

@Digits of Number Pi@


@题目描述-English@

Vasily has recently learned about the amazing properties of number π. In one of the articles it has been hypothesized that, whatever the sequence of numbers we have, in some position, this sequence is found among the digits of number π. Thus, if you take, for example, the epic novel “War and Peace” of famous Russian author Leo Tolstoy, and encode it with numbers, then we will find the novel among the characters of number π.

Vasily was absolutely delighted with this, because it means that all the books, songs and programs have already been written and encoded in the digits of π. Vasily is, of course, a bit wary that this is only a hypothesis and it hasn’t been proved, so he decided to check it out.

To do this, Vasily downloaded from the Internet the archive with the sequence of digits of number π, starting with a certain position, and began to check the different strings of digits on the presence in the downloaded archive. Vasily quickly found short strings of digits, but each time he took a longer string, it turned out that it is not in the archive. Vasily came up with a definition that a string of length d is a half-occurrence if it contains a substring of length of at least d/2 ⌊ d / 2 ⌋ , which occurs in the archive.

To complete the investigation, Vasily took 2 large numbers x, y (x ≤ y) with the same number of digits and now he wants to find the number of numbers in the interval from x to y, which are half-occurrences in the archive. Help Vasily calculate this value modulo 10^9 + 7.

Input
The first line contains string s consisting of decimal digits (1 ≤ |s| ≤ 1000) that Vasily will use to search substrings in. According to hypothesis, this sequence of digis indeed occurs in the decimal representation of π, although we can’t guarantee that.
The second and third lines contain two positive integers x, y of the same length d (x ≤ y, 2 ≤ d ≤ 50). Numbers x, y do not contain leading zeroes.
Output
Print how many numbers in the segment from x to y that are half-occurrences in s modulo 10^9 + 7.

Examples
input
02
10
19
output
2

input
023456789
10
19
output
9

input
31415926535
10
29
output
20

@题目大意@

定义某个字符串d在字符串s中“半出现”,如果d中存在一个长度>= lend/2 ⌊ l e n d / 2 ⌋ 的子串在s中出现。现在给你一个数字串s和两个高精度整数x和y,求有多少个数满足在区间[x,y]内且在s中半出现。

@解析@

首先如果做过相关的模板题,就会发现这道题一脸数位dp样……

然后再有一个突破口就是,“半出现”这个条件等价于包含至少一个s中所有长度为

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值