1 条题解
-
0问号 (周文浩) LV 10 @ 2024-4-1 17:32:26
#include <bits/stdc++.h> using namespace std; typedef long long LL; const int N = 30, mod = 1e9 + 7; LL p[N]; LL down = 1; int qmi(int a, int k) { int ret = 1; while (k) { if (k & 1) ret = 1ll * ret * a % mod; a = 1ll * a * a % mod; k >>= 1; } return ret; } int C(LL a, LL b) { if (a < b) return 0; int up = 1; for (LL i = a; i > a - b; i--) { up = i % mod * up % mod; } return up * down % mod; } int main() { LL n, m; scanf("%lld %lld", &n, &m); for (int i = 0; i < n; i++) { scanf("%lld", p + i); } for (int i = 1; i < n; i++) { down = down * i % mod; } down = qmi(down, mod - 2); int ret = C(m + n - 1, n - 1); for (int i = 1; i < 1 << n; i++) { LL a = m + n - 1, b = n - 1, cnt = 0; for (int j = 0; j < n; j++) { if (i >> j & 1) a -= p[j] + 1, cnt ^= 1; } if (cnt) ret = (ret - C(a, b)) % mod; else ret = (ret + C(a, b)) % mod; } printf("%d", (ret + mod) % mod); return 0; }
- 1
信息
- ID
- 125
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 9
- 标签
- 递交数
- 8
- 已通过
- 8
- 上传者