Pagini recente » Cod sursa (job #2384881) | Cod sursa (job #3148572) | Cod sursa (job #2519148) | Cod sursa (job #978168) | Cod sursa (job #2207895)
#include <fstream>
#include <iostream>
using namespace std;
ofstream fout("cowfood.out");
#define DIM 31
#define MOD 3210121
int lim[DIM];
int sol[DIM];
int N, K, S;
int s;
int nr_sol;
void Read();
void Back(int k);
int main()
{
Read();
Back(1);
fout << nr_sol;
fout.close();
return 0;
}
void Back(int k)
{
if (k > K)
{
nr_sol = (nr_sol + 1) % MOD;
return;
}
for (int i = 1; i < lim[k]; ++i)
{
if (s + i <= S)
{
sol[k] = i;
s += i;
Back(k + 1);
s -= i;
sol[k] = 0;
}
}
};
void Read()
{
ifstream fin("cowfood.in");
fin >> K >> S >> N;
int aux;
for (int i = 1; i <= N; ++i)
for (int j = 1; j <= K; ++j)
{
fin >> aux;
if (aux > lim[j])
lim[j] = aux;
}
fin.close();
};