Topic links: luogu6078
First, the subject can be converted to eat up \ (A \) number scheme candy.
Considered to write each jar take confectionery method generating function is \ (1 + x + x ^ 2 + \ cdots + x ^ m = \ frac {1-x ^ {m + 1}} {1-x} \) .
So the answer to the last generation function is:
The generating function of the first half at most \ (2 ^ n \) position has a value, in view of the \ (n-\) is small we can burst seized, assumed that the current found \ (x ^ y \) of non-zero coefficients, then that item back to its contribution is \ (\ sum_ {i = 0 } ^ {ay} \ dbinom {i + n-1} {i} = \ dbinom {ay + n} {ay} = \ dbinom + n-Y-a {} {} n-\) (As proof of identity of this combination, the number of combinations can be considered recursive / sense combinations)
Thus \ (x ^ y \) contribution may be (O (n) \) \ solved in time. Finally, pay attention to the problem modulo the number of combinations can be.
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 2004
#define eps 1e-8
inline int read()
{
int x=0,f=1;char ch=getchar();
while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
return x*f;
}
namespace My_Math{
#define N 100000
int fac[N+100],invfac[N+100];
int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
int mul(int x,int y) {return 1ll*x*y%maxd;}
ll qpow(ll x,int y)
{
ll ans=1;
while (y)
{
if (y&1) ans=mul(ans,x);
x=mul(x,x);y>>=1;
}
return ans;
}
int getinv(int x) {return qpow(x,maxd-2);}
void math_init()
{
fac[0]=invfac[0]=1;
rep(i,1,N) fac[i]=mul(fac[i-1],i);
invfac[N]=getinv(fac[N]);
per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
}
#undef N
}
using namespace My_Math;
int n,m,ans,v[12],a,b;
int C(int n,int m)
{
if ((n<m) || (n<0) || (m<0)) return 0;
ll ans=1,pro=1;
rep(i,1,m) pro=pro*i;
ll mod=pro*maxd;
rep(i,n-m+1,n)
ans=ans*(i%mod)%mod;
ans=(ans/pro)%mod;
return ans;
}
void dfs(int dep,int op,int now)
{
if (dep==n+1)
{
if (op&1) ans=dec(ans,C(n+m-now,n));
else ans=add(ans,C(n+m-now,n));
return;
}
dfs(dep+1,op,now);
dfs(dep+1,op+1,now+v[dep]);
}
int solve(int lim)
{
m=lim;ans=0;
dfs(1,0,0);
return ans;
}
int main()
{
n=read();a=read();b=read();
rep(i,1,n) v[i]=read()+1;
int ans=dec(solve(b),solve(a-1));
printf("%d\n",ans);
return 0;
}