Cod sursa(job #673929)

Utilizator tvararuVararu Theodor tvararu Data 5 februarie 2012 11:41:16
Problema Cowfood Scor 8
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;

int k, s, n, result = 0;
vector<int> tops, sol;

void back (int index, int sum)
{
	if (index == k)
	{
		result++;
	}
	else
	{
		sol[index] = 1;
		sum++;
		
		while (sum <= s && sol[index] < tops[index])
		{
			back (index + 1, sum);
			sol[index]++;
			sum++;
		}
	}
}

int main (int argc, char const *argv[])
{
	ifstream in ("cowfood.in");
	in >> k >> s >> n;
	sol.resize (k);
	tops.resize (k);
	for (int i = 0; i < n; i++)
	{
		for (int j = 0; j < k; j++)
		{
			int temp; in >> temp;
			if (temp > tops[j])
				tops[j] = temp;
		}
	}
	in.close ();
	
	back (0, 0);
	
	ofstream out ("cowfood.out");
	out << result;
	out.close ();
	
	return 0;
}