#include <stdio.h>
#define MAX_X 100
// Function to count combinations using backtracking
int countCombinations(int weights[], int start, int num_bags, int target_weight, int current_weight, int count) {
if (num_bags == 0) {
if (current_weight == target_weight) {
return 1;
}
return 0;
}
if (start >= MAX_X) {
return 0;
}
int ways = 0;
// Include the current sack in the combination
ways += countCombinations(weights, start + 1, num_bags - 1, target_weight, current_weight + weights[start], count);
// Exclude the current sack and move to the next
ways += countCombinations(weights, start + 1, num_bags, target_weight, current_weight, count);
return ways;
}
int main() {
int W, N, X;
int weights[MAX_X];
// Read inputs
for (int i = 0; i < X; i++) {
scanf("%d", &weights
[i
]); }
// Compute the number of valid combinations
int result = countCombinations(weights, 0, N, W, 0, 0);
// Print the result
return 0;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgojZGVmaW5lIE1BWF9YIDEwMAoKLy8gRnVuY3Rpb24gdG8gY291bnQgY29tYmluYXRpb25zIHVzaW5nIGJhY2t0cmFja2luZwppbnQgY291bnRDb21iaW5hdGlvbnMoaW50IHdlaWdodHNbXSwgaW50IHN0YXJ0LCBpbnQgbnVtX2JhZ3MsIGludCB0YXJnZXRfd2VpZ2h0LCBpbnQgY3VycmVudF93ZWlnaHQsIGludCBjb3VudCkgewogICAgaWYgKG51bV9iYWdzID09IDApIHsKICAgICAgICBpZiAoY3VycmVudF93ZWlnaHQgPT0gdGFyZ2V0X3dlaWdodCkgewogICAgICAgICAgICByZXR1cm4gMTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgaWYgKHN0YXJ0ID49IE1BWF9YKSB7CiAgICAgICAgcmV0dXJuIDA7CiAgICB9CgogICAgaW50IHdheXMgPSAwOwoKICAgIC8vIEluY2x1ZGUgdGhlIGN1cnJlbnQgc2FjayBpbiB0aGUgY29tYmluYXRpb24KICAgIHdheXMgKz0gY291bnRDb21iaW5hdGlvbnMod2VpZ2h0cywgc3RhcnQgKyAxLCBudW1fYmFncyAtIDEsIHRhcmdldF93ZWlnaHQsIGN1cnJl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