题解:CF1327E Count The Blocks
题意:
你将所有从
做法:
先打表找规律,设
| n | ans |
|---|---|
| 1 | 10 |
| 2 | 180 10 |
| 3 | 2610 180 10 |
| 4 | 34200 2610 180 10 |
| 5 | 423000 34200 2610 180 10 |
不难发现
接下来对于每个
-
块在开头:
1 \cdots i 都应该是一样的,10 种方案,然后i+1 不能填和前边一样的,9 种方案,i+2 \cdots n 没有限制,随便选,10^{n-i-1} 种方案。 -
块在结尾:同理,只是把在开头情况的整个序列翻转过来。
-
块在中间:块头不在整个序列开头或结尾,只有
n-i-1 个位置,这i 个数相同,有10 种方案,两边不能和中间一样,9\times9=81 种,其余随便放10^{n-i-2} 种。
全都加在一起得到:
Code.
把式子写成了一个更好看的形式。
#include<bits/stdc++.h>
const int mod=998244353;
#define int long long
using namespace std;
int n;
int sum=0;
int qpow(int a,int b){
int res=1;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=n;i>=2;i--){
cout<<qpow(10,i-2)*(81*i+18)%mod<<' ';
}
cout<<10;
return 0;
}