BZOJ 3027 [Ceoi2004]Sweet

生成函数

$(1+x+x^{2}+x^{3} \cdots +x^{m_i})=\frac{1-x^{m_{i}+1}}{1-x}$

$\prod_{i=1}^{n}\frac{1-x^{m_{i}+1}}{1-x}\\=(1+x+x^{2}+x^{3}+\cdots)^{n}\prod_{i=1}^{n}(1-x^{m_{i}+1})$

$$k \times (C_{n-1}^{n-1}+C_{1+n-1}^{n-1}+C_{2+n-1}^{n-1}+ \cdots +C_{a-y+n-1}^{n-1})$$

$$C_{a-y+n}^{n}=\frac{(a-y+n)!}{n!(a-y)!}=\frac{(a-y+n)^{\underline{n}}}{n!}$$

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int mm=2004;
const int maxn=20;

int n,mx,mi;
long long ans=0;
int a[maxn];

long long nt=1;

long long C(int n,int m){
if(n<0||m<0)return 0;
if(n<m)return 0;
long long ret=1;
for(int i=n-m+1;i<=n;++i)ret=ret*i%(mm*nt);
return ret/nt;
}

int limx;
long long Dfs(int x,int f,int t){
if(x==n+1){
long long ret=0;
return (f*C(limx-t+n,n)+mm)%mm;
}

return (Dfs(x+1,f,t)+Dfs(x+1,-f,t+a[x]+1))%mm;
}
long long GetAns(int m){
limx=m;
return Dfs(1,1,0);
}

int main(){
scanf("%d%d%d",&n,&mi,&mx);
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=n;++i)nt=nt*i;

ans=(GetAns(mx)-GetAns(mi-1)+mm)%mm;

cout<<ans<<endl;

return 0;
}


posted @ 2018-06-21 08:33  ws_zzy  阅读(272)  评论(0编辑  收藏  举报