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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
| #include<bits/stdc++.h> #define LL long long #define PII pair<int, int> #define int long long using namespace std; template <class T> inline void read(T &res) { res = 0; bool flag = 0; char c = getchar(); while('0' > c || c > '9') { if(c == '-') flag = 1; c = getchar();} while('0' <= c && c <= '9') res = (res << 3) + (res << 1) + (c ^ 48), c = getchar(); if(flag) res = -res; } template <class T, class ...Arg> inline void read(T &res, Arg &...com){ read(res), read(com...);} template <class T> void out(T res) { if(res > 9) out(res / 10); putchar(res % 10 + '0'); } template <class T> inline void write(T res) { if(res < 0) putchar('-'), res = -res; out(res), putchar('\n'); } const int N = 20, M = (1 << N) + 5, mod = 1e9 + 7; int n, m; LL a[N + 5]; int ans; inline int qpow(int x, int k) { int res = 1; while(k) { if(k & 1) res = 1ll * x * res % mod; x = 1ll * x * x % mod; k >>= 1; } return res; } inline int C(LL x, LL y) { if(x > y) return 0; x = min(y - x, x); int res = 1, a = 1, b = 1; for(int i = 1;i <= x;i ++) a = 1ll * a * (y - i + 1) % mod, b = 1ll * b * i % mod; res = 1ll * res * a % mod * qpow(b, mod - 2) % mod; return res; } inline int lucas(LL x, LL y) { if(x < mod && y < mod) return C(x, y); return 1ll * lucas(x / mod, y / mod) * C(x % mod, y % mod) % mod; } signed main() { read(n, m); for(int i = 1;i <= n;i ++) read(a[i]); for(int i = 0, cnt, sum;i < (1 << n);i ++) { cnt = sum = 0; for(int j = 1;j <= n;j ++) if((i >> j - 1) & 1) cnt ++, sum += a[j] + 1; if(sum > n + m - 1) continue; if(cnt & 1) ans = (ans - lucas(n - 1, m + n - sum - 1)) % mod; else ans = (ans + lucas(n - 1, n + m - sum - 1)) % mod; } write((ans + mod) % mod); return 0; }
|