Pagini recente » Cod sursa (job #1367556) | Cod sursa (job #233560) | Cod sursa (job #1278451) | Cod sursa (job #1852549) | Cod sursa (job #1020060)
#include<fstream>
#include<cstring>
#include<queue>
#define MOD 30103
using namespace std;
int K,A,B,nrcif,nr[210][210][110],poz[10][210],sol;
char N[210];
struct Stare{
int last,r;
Stare(int x,int y)
{
last=x;
r=y;
}
};
queue <Stare> Q,Q2;
bool bagat[210][210][110];
int main()
{
int i,j,lg;
Stare now = Stare(0,0);
ifstream fin("diviz.in");
fin>>K>>A>>B;
fin>>(N+1); nrcif=strlen(N+1);
fin.close();
for(i=0;i<10;i++)
poz[i][nrcif]=nrcif+1;
for(i=nrcif-1;i>=0;i--)
{
for(j=0;j<10;j++)
{
if(N[i+1]-'0'==j)
poz[j][i]=i+1;
else
poz[j][i]=poz[j][i+1];
}
}
for(i=0;i<10;i++)
{
if(poz[i][0]==nrcif+1)
continue;
nr[1][poz[i][0]][i%K]++;
if(nr[1][poz[i][0]][i%K]==1)
Q.push(Stare(poz[i][0],i%K));
}
lg=1;
while(lg<=B && !Q.empty())
{
while(!Q.empty())
{
now=Q.front();
Q.pop();
if(lg>=A && now.r==0)
{
sol+=nr[lg][now.last][now.r];
if(sol>=MOD)
sol-=MOD;
}
for(i=0;i<10;i++)
{
if(poz[i][now.last]!=nrcif+1)
{
nr[lg+1][poz[i][now.last]][(now.r*10+i)%K]+=nr[lg][now.last][now.r];
if(nr[lg+1][poz[i][now.last]][(now.r*10+i)%K]>=MOD)
nr[lg+1][poz[i][now.last]][(now.r*10+i)%K]-=MOD;
if(!bagat[lg+1][poz[i][now.last]][(now.r*10+i)%K])
{
bagat[lg+1][poz[i][now.last]][(now.r*10+i)%K]=true;
Q2.push(Stare(poz[i][now.last],(now.r*10+i)%K));
}
}
}
}
while(!Q2.empty())
{
now=Q2.front();
Q2.pop();
Q.push(now);
}
lg++;
}
ofstream fout("diviz.out");
fout<<sol<<"\n";
fout.close();
return 0;
}