Cod sursa(job #1189989)

Utilizator pufoseniePufosenie pufosenie Data 24 mai 2014 10:02:09
Problema Cowfood Scor 4
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.97 kb
#include <fstream>
using namespace std;

ifstream is("cowfood.in");
ofstream os("cowfood.out");

int n, k, s, cnt, nr, aux, sum;
bool a[450001] = {false};

void Work( int x );
void Write();

int main()
{
    is >> k >> s >> n;
    for ( int i = 1; i <= n; i++ )
    {
        for ( int j = 1; j <= k; j++ )
        {
            is >> nr;
            aux = aux * 10 + nr;
        }
        a[aux] = true;
        aux = 0;
    }
    Work(1);

    os << cnt;

    is.close();
    os.close();
    return 0;
}

void Work( int x )
{
    if( x > k )
    {
        if ( sum < s )
        {
            cnt++;
            cnt %= 3210121;
            return;
        }
        else
            return;
    }

    for( int i = 1; i <= s - k; i++ )
    {
        aux = aux * 10 + i;
        sum += i;
        if ( !a[aux] )
        {
            Work( x + 1 );
        }
            sum = sum - ( aux % 10 );
            aux /= 10;
    }
}