CodeForces - 1513C Add One

Posted 海岛Blog

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CodeForces - 1513C Add One相关的知识,希望对你有一定的参考价值。

C. Add One
time limit per test: 1 second
memory limit per test: 256 megabytes

You are given an integer n. You have to apply m operations to it.

In a single operation, you must replace every digit d of the number with the decimal representation of integer d+1. For example, 1912 becomes 21023 after applying the operation once.

You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 109+7.

Input
The first line contains a single integer t (1≤t≤2⋅105) — the number of test cases.

The only line of each test case contains two integers n (1≤n≤109) and m (1≤m≤2⋅105) — the initial number and the number of operations.

Output
For each test case output the length of the resulting number modulo 109+7.

Example
input
5
1912 1
5 6
999 1
88 2
12 100
output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.

For the second test, 5 becomes 21 after 6 operations which is of length 2.

For the third test, 999 becomes 101010 after 1 operation which is of length 6.

For the fourth test, 88 becomes 1010 after 2 operations which is of length 4.

问题链接CodeForces - 1513C Add One
问题简述:(略)
问题分析:(略)
AC的C++语言程序如下:

/* CodeForces - 1513C Add One */

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int MOD = 1e9 + 7;
const int N = 1e5 + 5;
LL dp[N * 2];

void init()
{
    for (int i = 0; i < 10; i++)
        dp[i] = 1;
    for (int i = 10; i < N * 2; i++)
        dp[i] = (dp[i - 9] + dp[i - 10]) % MOD;
}

int main()
{
    init();

    int t;
    scanf("%d", &t);
    while (t--) {
        int n, k;
        scanf("%d%d", &n, &k);

        LL ans = 0;
        while (n) {
            ans += dp[n % 10 + k];
            ans %= MOD;
            n /= 10;
        }

        printf("%lld\\n", ans);
    }

    return 0;
}

以上是关于CodeForces - 1513C Add One的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 620F. Xors on Segments

Codeforces 231CTo Add or Not to Add

CodeForces - 237C Primes on Interval(二分+尺取)

[Codeforces 1286B] Numbers on Tree | 技巧构造

codeforces 220 C. Game on Tree

codeforces727E Games on a CD