Pagini recente » Cod sursa (job #869213) | Cod sursa (job #669859) | Cod sursa (job #2436237) | Cod sursa (job #695636) | Cod sursa (job #2618795)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("diviz.in");
ofstream fout("diviz.out");
const int nmax = 200, mod = 30103;
int k, a, b, n, v[nmax + 5], dp[11][nmax + 3][103], pos[10][nmax + 3], aux[nmax + 5][nmax + 5];
char ch;
int main()
{
fin >> k >> a >> b;
while (fin >> ch) v[++n] = ch - '0';
for (int j = 0; j <= 9; ++j)
{
for (int i = a; i <= b; ++i)
{
dp[j][i][0] = 1;
}
pos[j][n + 1] = n + 1;
}
for (int i = 0; i <= 9; ++i)
{
for (int j = n; j >= 1; --j)
{
if (v[j] == i) pos[i][j] = j;
else pos[i][j] = pos[i][j + 1];
}
}
int rez;
for (int index = n; index >= 1; --index)
{
if (index < n)
{
for (int cif = n; cif >= 0; --cif)
{
for (int nr = k - 1; nr >= 0; --nr)
{
dp[v[index]][cif][nr] = aux[cif][nr];
}
}
}
for (int cif = n; cif >= 0; --cif)
{
for (int nr = k - 1; nr >= 0; --nr)
{
int ans = (cif >= a && cif <= b && nr == 0 ? 1 : 0);
int start = 0;
if (cif == 0) ++start;
for (int c = start; c <= 9; ++c)
{
int next = pos[c][index];
if (next <= n) ans = (1LL * ans + dp[c][cif + 1][(nr * 10 + c) % k]) % mod;
}
aux[cif][nr] = ans;
rez = ans;
}
}
}
fout << rez;
fin.close();
fout.close();
return 0;
}