CodeForces-1327 E. Count The Blocks Combinatorics

E. Count The Blocks combinatorics

Original title address:

http://codeforces.com/contest/1327/problem/E

Basic questions:

Find out [ 0 ,10 ^ (n - 1) ]with the number of leading zeros in the range of a length of 2, 3, ..., n defines the number of blocks, the block is as follows:
For example: 000 2 77 34 is 000 then we record blocks of length 3 The number is 2, the number of blocks of length 2 is 1, and the number of blocks of length 1 is 3.

The basic idea:

We can know that we want to calculate all occurrences of consecutive subsequences of length i in a sequence of length n;

For example: n = 10, i = 3 Then we can know the following situations:

  1. Similar 0 2 111 . 3 4523 In this case we can see the bold continuous portion combinations are possible 10species, the sequence can be inserted in any (n - i - 1)position on the combination of the left and right sides have italicized 9 * 9species, there is a combination of the rest of 10 ^ (n-i-2)species;
  2. Similarly 333 . 8 235 323 such a case, there supra bold combinations 10species, in combination with a position italic 9types, the placement of 2the edge, and the remainder combination 10 ^ (n - i - 1)species;
  3. Summary of two or more kinds of reduction, for a given n, the following formula can be obtained:
    ans[i] = (n - i - 1) * 10^(n - i - 1) * 81 + 18 * 10^(n - i).

Reference Code:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
using namespace std;
#define IO std::ios::sync_with_stdio(false)
#define int long long
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)
#define mset(s, _) memset(s, _, sizeof(s))
#define pb push_back
#define pii pair <int, int>
#define mp(a, b) make_pair(a, b)
#define INF 0x3f3f3f3f
inline int read() {
    int x = 0, neg = 1; char op = getchar();
    while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); }
    while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); }
    return neg * x;
}
inline void print(int x) {
    if (x < 0) { putchar('-'); x = -x; }
    if (x >= 10) print(x / 10);
    putchar(x % 10 + '0');
}
const int maxn = 2e5 + 10;
const int mod = 998244353;
int n,pw[maxn],ans[maxn];
signed main() {
    IO;
    cin >> n;
    pw[0] = 1;
    for(int i = 1 ; i <= n ; i++) pw[i] = pw[i-1] * 10 % mod;
    for(int i = 1 ; i <= n ;i++){
        if(i == n) { ans[i] = 10; continue; }
        ans[i] = pw[n - i - 1] * 81 % mod * (n - i - 1) % mod + pw[n - i] * 18 % mod;
        ans[i] %= mod;
    }
    for(int i = 1 ; i <= n ; i++) cout << ans[i] << " ";
    cout << endl;
    return 0;
}
Published 23 original articles · praised 7 · visits 1739

Guess you like

Origin blog.csdn.net/weixin_44164153/article/details/105095134