Pagini recente » Cod sursa (job #533046) | Cod sursa (job #3040943) | Cod sursa (job #1790851) | Cod sursa (job #2484846) | Cod sursa (job #1189989)
#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;
}
}