Cod sursa(job #2618788)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 26 mai 2020 11:39:00
Problema Diviz Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.86 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("diviz.in");
ofstream fout("diviz.out");

const int nmax = 200, mod = 98551;
int k, a, b, n, v[nmax + 5], pos[10][nmax + 5], dp[11][nmax + 5][nmax + 5], dp2[11][nmax + 5][nmax + 5];
char ch;
int solve(int index, int cif, int nr)
{
    if (index == n + 1) return cif >= a && cif <= b && nr == 0;
    int start = 0;
    if (cif == 0) ++start;
    int ans = solve(n + 1, cif, nr);
    for (int i = start; i <= 9; ++i)
    {
        int next = pos[i][index];
        if (next <= n) ans += solve(next + 1, cif + 1, (nr * 10 + i) % k);
    }
    return ans;
}
int main()
{
    fin >> k >> a >> b;
    while (fin >> ch) v[++n] = ch - '0';
    for (int j = a; j <= b; ++j)
    {
        dp[10][j][0] = 1;
    }

    fout << solve(1, 0, 0);
    fin.close();
    fout.close();
    return 0;
}