1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #include <iostream> using namespace std; int n, s, cnt; int arr[1000]; void dfs(int idx, int sum) { if (idx > n) return; if (sum > s) return; if (sum == s) { ++cnt; return; } dfs(idx + 1, sum + arr[idx]); dfs(idx + 1, sum); } int main() { cin >> n >> s; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (arr[i] > arr[j]) swap(arr[i], arr[j]); dfs(0, 0); cout << cnt << endl; return 0; } | cs |