Cod sursa(job #2047947)

Utilizator radu.leonardoThe Doctor radu.leonardo Data 25 octombrie 2017 17:19:30
Problema Diviz Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.31 kb
#include <bits/stdc++.h>
#define MOD 30103
using namespace std;
ifstream f("diviz.in");
ofstream g("diviz.out");

int K,A,B,N,Ans;
int DP[201][201][101];
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];
        DP[1][First[digit][1]][digit%K]=1; }

    for (int lenght=1; lenght<=B; lenght++)
        for (int position=lenght; position<=N; position++)
            for (int remainder=0; remainder<K; remainder++)
                if (DP[lenght][position][remainder]!=0)
                    for (int newdigit=0; newdigit<=9; newdigit++)
                        if (First[newdigit][position+1]!=0)
                            DP[lenght+1][First[newdigit][position+1]][(remainder*10+newdigit)%K]+=DP[lenght][position][remainder],
                            DP[lenght+1][First[newdigit][position+1]][(remainder*10+newdigit)%K]%=MOD;

    for (int lenght=A; lenght<=B; lenght++)
        for (int position=lenght; position<=N; position++)
            Ans+=DP[lenght][position][0],
            Ans%=MOD;

    g<<Ans; }