Skip to content

Instantly share code, notes, and snippets.

@hikariyo
Created December 14, 2025 12:40
Show Gist options
  • Select an option

  • Save hikariyo/685bcfa6d16848155897fd438fb14770 to your computer and use it in GitHub Desktop.

Select an option

Save hikariyo/685bcfa6d16848155897fd438fb14770 to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 22, P = 1e9+7;
int f[N], s;
int n;
map<int, int> F;
int qpow(int a, int k) {
int res = 1;
while (k) {
if (k & 1) res = res * a % P;
a = a * a % P;
k >>= 1;
}
return res;
}
int C(int m, int n) {
int res = 1;
for (int j = 0; j < n; j++) res = res * ((m - j) % P) % P;
int fact = 1;
for (int j = 1; j <= n; j++) fact = fact * j % P;
return res * qpow(fact, P-2) % P;
}
signed main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
cin >> n >> s;
for (int i = 0; i < n; i++) cin >> f[i];
for (int S = 0; S < 1 << n; S++) {
int idx = 0, val = 1;
for (int i = 0; i < n; i++) {
if (S >> i & 1) {
idx += f[i] + 1;
val = -val;
}
}
F[idx] = (F[idx] + P + val) % P;
}
int ans = 0;
for (const auto& [i, fi]: F) {
// [x^s] F(x) / (1-x)^n
int m = s - i;
if (m < 0) continue;
ans = (ans + fi * C(m+n-1, n-1)) % P;
}
cout << ans << '\n';
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment