Pagini recente » Cod sursa (job #1277086) | Cod sursa (job #2925797) | Cod sursa (job #1405319) | Cod sursa (job #3159334) | Cod sursa (job #2051082)
#include <bits/stdc++.h>
#define MOD 30103
using namespace std;
ifstream f("diviz.in");
ofstream g("diviz.out");
int K,A,B,N,Ans;
unsigned short DP[2][101][201];
int First[11][201];
char S[202];
int main() {
f>>K>>A>>B>>(S+1);
N=strlen(S+1);
for (int digit=0; digit<=9; digit++)
for (int position=N; position>=1; position--)
if (S[position]-'0'==digit)
First[digit][position]=position;
else First[digit][position]=First[digit][position+1];
for (int digit=1; digit<=9; digit++)
DP[1][digit%K][First[digit][1]]=1;
for (int lenght=1; lenght<=B; lenght++) {
memset(DP[(lenght+1)&1],0,sizeof(DP[(lenght+1)&1]));
for (int position=lenght; position<=N; position++) {
for (int remainder=0; remainder<K; remainder++)
if (DP[lenght&1][remainder][position]!=0)
for (int newdigit=0; newdigit<=9; newdigit++)
if (First[newdigit][position+1]!=0)
DP[(lenght+1)&1][(remainder*10+newdigit)%K][First[newdigit][position+1]]+=DP[lenght&1][remainder][position],
DP[(lenght+1)&1][(remainder*10+newdigit)%K][First[newdigit][position+1]]%=MOD;
if(lenght>=A)
Ans+=DP[lenght&1][0][position],
Ans%=MOD; } }
g<<Ans; }