Cod sursa(job #2835705)

Utilizator puica2018Puica Andrei puica2018 Data 19 ianuarie 2022 09:45:41
Problema Diviz Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.08 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("diviz.in");
ofstream fout("diviz.out");

const int mod=30103;

int k,a,b;
int sz,nr[205];
int dp[205][205][105],f[10][205];

int main()
{
    fin>>k>>a>>b;
    char ch;
    while(fin>>ch)
        nr[++sz]=ch-'0';
    for(int i=0; i<10; i++)
    {
        int last=0;
        for(int j=sz; j>=0; j--)
        {
            f[i][j]=last;
            if(nr[j]==i)
                last=j;
        }
    }
    for(int i=1; i<10; i++)
        dp[1][f[i][0]][i%k]=1;
    for(int j=1; j<sz; j++)
    {
        for(int i=j; i<=sz; i++)
        {
            for(int r=0; r<k; r++)
            {
                for(int cif=0; cif<9; cif++)
                {
                    if(f[cif][i]>0)
                        dp[j+1][f[cif][i]][(r*10+cif)%k]=(dp[j+1][f[cif][i]][(r*10+cif)%k]+dp[j][i][r])%mod;
                }
            }
        }
    }
    int sum=0;
    for(int j=a; j<=b; j++)
        for(int i=j; i<=sz; i++)
            sum=(sum+dp[j][i][0])%mod;
    fout<<sum<<"\n";
    return 0;
}