Cod sursa(job #2207895)

Utilizator fetti_danutzdezactivat fetti_danutz Data 27 mai 2018 11:23:58
Problema Cowfood Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.79 kb
#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();
};