//Answer on Question#44998 - Progamming - C++
#include <iostream>
using namespace std;
int main() {
int T;
cin >> T;
while (T-- > 0) {
static const int MAX_N = 20;
static const int MAX_X = 500;
int N, X;
cin >> N >> X;
int C[MAX_N];
for (int i = 0; i < N; ++i) {
cin >> C[i];
}
long long d[MAX_N + 1][MAX_X + 1]; // d[i][j] is the number of possibilities to get j gredits using a subset only from the first i subjects
d[0][0] = 1;
for (int i = 1; i < X + 1; ++i) {
d[0][i] = 0;
}
for (int i = 1; i < N + 1; ++i) {
for (int j = 0; j < X + 1; ++j) {
// d[i][j] is the sum of possibilities when we take the i-th subject and don'ttake it
d[i][j] = d[i - 1][j]; // we can not take the i-th subject and the number of credits won't change
if (j >= C[i - 1]) d[i][j] += d[i - 1][j - C[i - 1]]; // we can take the i-th subject and from the number of required credits substract the number of credits of the i-th subject
}
}
cout << d[N][X] << endl;
}
}
Comments
Leave a comment