RT,WA on test 5,求大佬帮忙看一下/kel
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int P = 1e9 + 7;
const int MAXN = 20;
int n, s;
int ans, cnt, sum;
int f[MAXN + 5];
int inv[MAXN + 5];
int Power(int a, int b)
{
int res = 1;
while(b > 0){
if((b & 1) == 1) res = res * a % P;
a = a * a % P;
b >>= 1;
}
return res;
}
void Init(int n)
{
for(int i = 1; i <= n; i ++) inv[i] = Power(i, P - 2);
}
int C(int a, int b)
{
if(a < 0 || b < 0 || a < b) return 0;
if(a == 0 || b == 0) return 1;
int res = 1;
for(int i = a - b + 1; i <= a; i ++) res = res * i % P;
for(int i = 1; i <= b; i ++) res = res * inv[i] % P;
return res;
}
signed main()
{
Init(MAXN);
scanf("%lld%lld", & n, & s);
for(int i = 1; i <= n; i ++) scanf("%lld", & f[i]);
ans = 0;
for(int S = 0; S < (1 << n); S ++){
cnt = 0, sum = 0;
for(int i = 1; i <= n; i ++) if(((S >> (i - 1)) & 1) == 1) cnt ++, sum += f[i];
if(cnt + sum > s) continue;
ans = (ans + (((cnt & 1) == 0) ? 1 : - 1) * C(s - cnt - sum + n - 1, n - 1) + P) % P;
}
printf("%lld\n", ans);
return 0;
}