1 条题解
-
0
http://blog.csdn.net/tenkuo/article/details/149705924?spm=1001.2014.3001.5501 这是hansang写的神秘题解。
#include<bits/stdc++.h> using namespace std; typedef long long LL; template<typename T> void qread(T &x){ //我流快读 x=0; int f=1; char c=getchar(); for(; !isdigit(c); c=getchar()) if(c=='-') f=-1; for(; isdigit(c); c=getchar()) x=x*10+(c-'0'); x*=f; } const int N=15; const LL P=2004; LL a[N], fac, ans; int n; LL C(int x, int y){ //注意!!x 比 y 大!! LL res=1, eP=P*fac; for(int i=x; i>=x-y+1; i--) res=(res*i)%eP; return res/fac; } void dfs(int step, LL sum, int pow, LL lim){ //分别是当前在计算第几种糖,目前的系数的乘积,累计 x的幂次,当前幂次最大限制 if(pow>lim) return ; //乘积幂次超限制了,没救了 if(step>n){ //所有糖都过完了 ans=(ans+sum*C(n+lim-pow, n)%P)%P; return ; } dfs(step+1, sum, pow, lim); //不选当前这个糖罐 dfs(step+1, -sum, pow+a[step]+1, lim); //选当前这个糖罐 //为啥是pow+a[step]+1? 看公式 } LL calc(LL x){ ans=0; dfs(1, 1, 0, x); return (ans%P+P)%P; //相减后可能是负数加个P } int main(){ qread(n); LL l, r; qread(l); qread(r); //换了个变量 fac=1; for(int i=1; i<=n; i++){ qread(a[i]); fac*=i; //顺便把阶乘搞了,这里作为除数可不能 mod!! } printf("%lld\n", (calc(r)-calc(l-1)+P)%P); //相减后可能是负数加个P return 0; }
- 1
信息
- ID
- 4692
- 时间
- 100ms
- 内存
- 128MiB
- 难度
- 10
- 标签
- 递交数
- 8
- 已通过
- 4
- 上传者