全都是m+n-1,下图都写成m-n-1了,没有脑子o(╥﹏╥)o
题目链接:214. Devu和鲜花 - AcWing题库
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int mod = 1e9+7;
ll A[25];
ll Pow(ll a, ll k){
ll ans = 1;
while(k){
if(k & 1) ans = ans*a%mod;
a = a*a%mod;
k>>=1;
}
return ans;
}
ll down = 1;
ll C(ll a, ll b) {
if(a<b) return 0;
ll up = 1;
for (ll i = a; i>=(a-b+1); i--) up = i%mod *up %mod;
return up * Pow(down, mod-2)%mod;
}
int main(){
int n; scanf("%d", &n);
ll m; scanf("%lld", &m);
for(int i=0; i<n; i++) scanf("%lld", &A[i]);
for(ll j = 1; j <= n-1; j++) down = j*down%mod;
ll res = 0;
for(int i=0; i< 1<<n; i++) { //2^n, 用二进制来表示这一对组合
ll a = m + n - 1, b = n - 1;
int sign = 1;
for(int j = 0; j < n; j++) //代表n个东西
if(i >> j & 1) { //i的这一位是1, 则选
sign *= -1; //容斥,奇正偶负
a -= A[j]+1;
}
res = ((res + C(a, b) * sign)%mod + mod)%mod;
}
cout << (res + mod)%mod;
return 0;
}