「Ceoi2004」Sweet
作者:互联网
\[ \begin{align} ans&=\prod_{i=1}^{n} (1+x+x^2+\cdots+x^{M[i]})\\ &=\prod_{i=1}^{n}{(x^{M[i]+1}-1)\over x-1}\\ &=(1-x)^{-n}\prod_{i=1}^{n}(1-x^{M[i]+1}) \end{align} \]
\[ (1-x)^{-n}=\sum_{k=0}^{+\infty}C_{n+k-1}^{n-1}x^k \]
对于\(\prod_{i=1}^{n}(1-x^{M[i]+1})\)的一项\(x^i\)
贡献为
\[
\sum_{k=a-i}^{b-i} C_{n+k-1}^{n-1}
\]
而
\[
\sum_{k=0}^{lim} C_{n+k}^k=C_{n+lim+1}^{lim}
\]
故复杂度为\(o(2^n)\)
#include <bits/stdc++.h>
//#pragma GCC target("avx,avx2,sse4.2")
#define rep(q, a, b) for (int q = a, q##_end_ = b; q <= q##_end_; ++q)
#define dep(q, a, b) for (int q = a, q##_end_ = b; q >= q##_end_; --q)
#define mem(a, b) memset(a, b, sizeof a)
#define debug(a) cerr << #a << ' ' << a << "___" << endl
using namespace std;
// char buf[10000000], *p1 = buf, *p2 = buf;
#define Getchar() getchar()//p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 10000000, stdin), p1 == p2) ? EOF : *p1++
void in(int &r) {
static char c;
r = 0;
while (c = Getchar(), c < 48);
do
r = (r << 1) + (r << 3) + (c ^ 48);
while (c = Getchar(), c > 47);
}
const int mod=2004;
int val[15];
int mul;
long long Mod;
int C(int a,int b){
if(b>a)return 0;
long long v=1;
rep(q,a-b+1,a)v=1LL*v*q%Mod;
return v/mul;
}
int a,b;
int n;
int ans;
void dfs(int x,int len,int v){
if(x==n+1){
ans=(ans+v*(C(n+b-len,n)-C(n+a-len-1,n)))%mod;
return;
}
dfs(x+1,len,v);
dfs(x+1,len+val[x]+1,-v);
}
int gcd(int a,int b){
return !b?a:gcd(b,a%b);
}
int main(){
in(n),in(a),in(b);
mul=1;
rep(q,1,n)in(val[q]),mul*=q;
Mod=1LL*mul*mod;
dfs(1,0,1);
ans=(ans+mod)%mod;
cout<<ans<<endl;
return 0;
}
标签:int,Sweet,len,Ceoi2004,dfs,ans,mul,mod 来源: https://www.cnblogs.com/klauralee/p/11692591.html