Pagini recente » Cod sursa (job #3200173) | Cod sursa (job #517270) | Cod sursa (job #560297) | Cod sursa (job #506352) | Cod sursa (job #2051078)
#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[201][101][2];
int First[11][201];
char S[202];
void Clear(int state) {
for(int i=1; i<=N; i++)
for(int j=0; j<K; j++)
DP[i][j][state]=0; }
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][First[digit][1]][digit%K]=1;
for (int lenght=1; lenght<=B; lenght++) {
Clear((lenght+1)&1);
for (int position=lenght; position<=N; position++) {
for (int remainder=0; remainder<K; remainder++)
if (DP[position][remainder][lenght&1]!=0)
for (int newdigit=0; newdigit<=9; newdigit++)
if (First[newdigit][position+1]!=0)
DP[First[newdigit][position+1]][(remainder*10+newdigit)%K][(lenght+1)&1]+=DP[position][remainder][lenght&1],
DP[First[newdigit][position+1]][(remainder*10+newdigit)%K][(lenght+1)&1]%=MOD;
if(lenght>=A)
Ans+=DP[position][0][lenght&1],
Ans%=MOD; } }
g<<Ans; }