E. Count The Blocks
Link: E. Count The Blocks
Description
You wrote down all integers from 0 to , padding them with leading zeroes so their lengths are exactly n. For example, if then you wrote out 000, 001, ..., 998, 999.
A block in an integer x is a consecutive segment of equal digits that cannot be extended to the left or to the right.
For example, in the integer there are three blocks of length , one block of length and two blocks of length .
For all integers from to count the number of blocks of length among the written down integers.
Since these integers may be too large, print them modulo .
Input
The only line contains one integer ().
Output
In the only line print integers. The -th integer is equal to the number of blocks of length .
Since these integers may be too large, print them modulo .
Examples
input
1
output
10
input
2
output
180 10
Problem solving
这道题的意思就是给你一个数,让你往这n位上面随意放置这个数字。问你所有摆放情况中,每种长度个相邻且相等的子串的个数。(中有个长度为的(),个长度为的())
排列组合的问题,我们分情况考虑一下。假设现在求得是长度为的子串个数
- 这个串在最左边或者最右边。此时这个长度为的子串有种情况(),与这个子串相邻的下(上)一位不能和它相等,若相等长度就是了。所以只有种情况。剩下的位这个数可以随便填。所以这种情况下的长度为的字串个数,乘是因为可以在左右两边。
- 这个串处于中间。此时这个长度为的子串也是有种情况(),与它相邻的两位,都只有种情况。剩下的位可以随便填。在长度为的串中长度为的子串个数为,但是左右两边的不是这种情况讨论的,所以还剩下种。所以这种情况下的长度为的子串个数。
将两种情况得到的答案加起来即可。长度为的情况比较特殊我们直接输出就好了。
可能是我高中数学或者概率论没有学好吧,这种题(一言难尽)
Code
#include<bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define mp make_pair const int maxn = 2e5 + 10; const int mod = 998244353; ll ten[maxn]; int main() { ios::sync_with_stdio(0); ten[0]=1; for(int i=1;i<maxn;i++) ten[i]=ten[i-1]*10%mod; ll n; cin>>n; for(int i=1;i<n;i++){ ll ans=(2ll*9ll*ten[n-i]%mod+9ll*9ll*ten[n-i-1]*(n-i-1)%mod)%mod; cout<<ans<<" "; } cout<<10<<endl; return 0; }