Untitled
unknown
plain_text
2 years ago
706 B
9
Indexable
#include<iostream>
using namespace std;
int Map[21][21];
int S,K,N;
int ans;
void bt(int col, int minScore, int sum){
if(col==K){
if(sum == S){
ans++;
return;
}
return;
}else{
for(int i=0; i<N; i++){
if(Map[i][col] >= minScore && sum+minScore<= S){
bt(col+1, Map[i][col],sum+Map[i][col]);
}
}
}
}
int main(){
freopen("Text.txt", "r", stdin);
int tc;
cin >> tc;
for(int t=1; t<=tc; t++){
cin >> S >> K >> N;
ans=0;
for(int i=0; i<N; i++){
for(int j=0; j<K; j++){
cin>> Map[i][j];
}
}
bt(0,0,0);
cout << "Case " << t << endl;
if(ans>0)
cout << ans << endl;
else
cout << "-1" << endl;
}
return 0;
}Editor is loading...
Leave a Comment