[ create a new paste ] login | about

Link: http://codepad.org/leOBU0AF    [ raw code | output | fork ]

hoaithu.melody - C++, pasted on Jun 26:
// Score

#include <iostream>
using namespace std;

#define FOR(i, a, b) for(int i = a; i <= b; i++)
#define maxN 21

int S, K, N;
int score[maxN][maxN];
int count;

void backtrack(int x, int sum, int a)
{
	if(x > K) 
	{
		if(sum == S)
			count++;
		return;
	}
	FOR(i, 1, N)
	{
		if(score[i][x] >= a && sum < S)  
			backtrack(x+1, sum + score[i][x], score[i][x]);
	}
}

int main()
{
	int T;
	cin >> T;
	FOR(testcase, 1, T)
	{
		count = 0;
		cin >> S >> K >> N;
		FOR(row, 1, N)
		{
			FOR(col, 1, K)
			{
				cin >> score[row][col];
			}
		}
		backtrack(1, 0, 0);
		if(count == 0)
			cout << "Case " << testcase << endl << "-1" << endl;
		else
			cout << "Case " << testcase << endl << count << endl;
	}
	return 0;
}


Output:
1
2
3
In function 'void backtrack(int, int, int)':
Line 18: error: reference to 'count' is ambiguous
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: