Cod sursa(job #1890615)

Utilizator Mihai_PredaPreda Mihai Dragos Mihai_Preda Data 23 februarie 2017 13:02:28
Problema Diviz Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.37 kb
#include <iostream>
#include <fstream>
#include <cstring>

using namespace std;

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

const int szMax = 205;
const int kMax = 105;
const int MOD = 30103;

int k, a, b, sz;
char v[szMax];
unsigned short dp[szMax][kMax][szMax];
bool viz[10];

void citire()
{
    in >> k >> a >> b;
    in >> v;
    sz = strlen(v);

    for(int i = 0; i < sz; ++i)
        v[i] -= '0';
}

void rezolvare()
{
    for(int i = 0; i < sz; ++i)
    {
        if(v[i] != 0)
            dp[i][v[i] % k][1] = 1;
    }
    int x, y;
    for(int i = 0; i < sz; ++i)
    {
        for(int j = i + 1; j < sz; ++j)
        {
            if(viz[v[j]] == true)
                continue;
            viz[v[j]] = true;
            for(int r = 0; r < k; ++r)
                for(int c = 1; c <= i + 1; ++c)
                {
                    x = (r * 10 + v[j]) % k;
                    y = c + 1;
                    dp[j][x][y] = (dp[j][x][y] + dp[i][r][c]) % MOD;
                }
        }
        for(int j = 0; j <= 9; ++j)
            viz[v[j]] = false;
    }

}

void afisare()
{
    int rasp = 0;
    for(int i = 0; i < sz; ++i)
        for(int j = a; j <= b; ++j)
            rasp = (rasp + dp[i][0][j]) % MOD;
    out << rasp;
}

int main()
{
    citire();
    rezolvare();
    afisare();
    return 0;
}