Codeforces 1327 E. Count The Blocks

Codeforces 1327 E. Count The Blocks

思路:

考虑\(n\)位数字。

假设说现在考虑块为\(i\)时候的答案。

\(i=n\)

那就只有\(00...0,11...1,...,99...9\)这样的答案,所以输出\(10\)

\(i<n\)的情况:

这连续的\(i\)个数字可以卡在\(n\)的左右两端,此时还剩\(n-i\)个数字没有用。

很明显与这\(i\)个数字相邻的那一个数字只能取\(9\)种可能,不相邻的\(n-i-1\)个数字有\(10^{n-i-1}\)种可能,然后连续段有\(10\)种可能。

所以此时的答案就是:

\[10\times 10^{n-i-1}\times 9=10^{n-i} \times 9 \]

当连续的\(i\)处于中间位置,那么此时也是有\(n-i\)个数字没有用,此时两端的两个数字只能取\(9\)种可能,剩余的数字可以取\(10^{max\{0,n-i-2\}}\)种可能,连续的\(i\)\(10\)种可能,所以最后结果为:

\[10\times 10^{n-i-2}\times 9^2=10^{n-i-1}\times 9^2 \]

相加即为答案。

fact[0] = 1;
for(int i = 1; i <= n; i++)
	fact[i] = (fact[i-1]*10)%mod;
for(ll i = 1; i <= n; i++)
{
	if(i == n) puts("10");
	else
    {
        ll t1 = n-i-1, t2 = 2;
        t1 = fact[n-i-1]%mod*t1%mod*9*9%mod;
        t2 = t2%mod*9*fact[n-i]%mod;
        cout << (t1+t2)%mod << " ";
    }
}
posted @ 2020-03-24 11:56  zhaoxiaoyun  阅读(344)  评论(0编辑  收藏  举报