Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
812 B
2
Indexable
Never
#include<iostream>
using namespace std;
int A[100][100];
int s,k,n;
int result;
int backtrack(int ck, int totalScore, int pre){
	if(ck==k){
		if(totalScore==s){
			result++;
			return 0;
		}
		
	}
	else{
		for(int i=1; i<=n;i++){
			if(A[i][ck+1]>=pre && (totalScore+A[i][ck+1])<=s){
				backtrack(ck+1, totalScore+A[i][ck+1], A[i][ck+1]);
			}
		}
		return -1;
	}
}
int main(){
	freopen("in.txt", "r", stdin);
	int t;
	cin>>t;
	for(int tc=1; tc<=t; tc++){
		cin>>s>>k>>n;
		
		for(int i=1; i<=n; i++){
			for(int j=1; j<=k; j++) cin>>A[i][j];
		}
		cout<<"Case "<<tc<<endl;
		for(int i=1; i<=n; i++){
			result=0;
			int h= backtrack(i,A[i][1],A[i][1]);
			//cout<<result<<endl;
		}
		if(result==0) result = -1;
		else result = 1;
		cout<<result<<endl;
	}
	return 0;
}