题解:CF1513C Add One

· · 题解

Code:

#include <bits/stdc++.h>
#define int long long
using namespace std;

const int mod = 1e9 + 7;
int dp[10][200005];

signed main() {
    ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    for (int j = 0; j <= 200000; j ++) {
        for (int i = 0; i <= 9; i ++) {
            if (i + j <= 9) dp[i][j] = 1;
            else dp[i][j] = (dp[1][i + j - 10] + dp[0][i + j - 10]) % mod;
        }
    }
    string n;
    int T, m;
    cin >> T;
    while (T --) {
        cin >> n >> m;
        int ans = 0;
        for (int i = 0; i < n.size(); i ++) ans = (ans + dp[n[i] - '0'][m]) % mod;
        printf("%d\n", ans);
    }
    return 0;
}