Codeforces 1327E. Count The Blocks【数学题】

传送门

题意

统计从 \(00...0\)\(99...9\)\(10^n-1\) 个数中出现的块长为 \(1,2,...,n\) 的块的个数各为多少。

题解

这道题不算难,昨晚没做出来实在是太蠢了,得好好反思。

对于长度 \(i\) 的块,直接考虑处于不同位置时对答案的贡献。

如果 \(n=i\),显然为 \(f[i]=10\)

如果 \(n=i+1\),那么 \(f[i]=10*9+9*10\)

如果 \(n>i+1\),那么 \(f[i]=10*9*10^{n-i-1}+10*9*9*10^{n-i-2}*(n-i-2+1)+10*9*10^{n-i-1}\)

代码

#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define ff first
#define ss second
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=3e5+10;
const int M=1e6+10;
const int mod=998244353;
int n;
LL f[N],po[N];

int main(){
	scanf("%d",&n);
	po[0]=1;
	for(int i=1;i<=n;i++) po[i]=po[i-1]*10%mod;
	for(int i=1;i<=n;i++){
		if(i==n) f[i]=10;
		else{
			f[i]=po[n-i-1]*10*9*2%mod;
			if(i+1+1<=n)
				f[i]=(f[i]+po[n-i-2]*10*9*9*(n-i-1))%mod;
		}
		printf("%lld ",f[i]);
	}
	return 0;
}

猜你喜欢

转载自www.cnblogs.com/BakaCirno/p/12556916.html