【GDKOI2017模拟1.21】Equation
2017-01-21 20:32
441 查看
Description
听着自己美妙的曲子,小Z进入了梦乡。在梦中,小Z仿佛又回到了自己纵横考场的年代。在梦中,小Z参加了一场考试,这场考试一共有n道题,每道题的最终得分都是一个大于等于0的整数。然而醒来后,小Z忘记了自己每道题的得分。他只记得自己计算过m次一些题目的分数和,每道题都被计算过,并且只被计算过一次。除此之外他还记得其中t道题的满分分别是多少(一道题的得分不会超过满分)。现在小Z想知道他这场考试有多少种得分情况(至少有一道题的得分不同就算不同的情况),因为这个答案可能很大,你只需要输出答案对1,000,000,007取模后的结果即可。Solution
这题的70分很好拿,打完之后就没有仔细想了。把n个数拆成m份,且这些可以为空,那么直接用隔板法Cn−1n+m−1
现在有限制的话,那么明显是容斥。
任意两个等式之间是互不影响的,所以对每个等式都进行容斥。
假设现在这个等式要求x≤r,除了x设其他数的和为sum,等式要求x+sum=R。
我们现在要求x强制爆出限制,那么就是强制要求x>=r+1,那么我们现在先强制在x那里填上x+1,其他的随便填,那么就是要求sum=R-r-1,那么方案数为Cq−1R−r−1+q−1,q为这个等式的元素数量。
然后容斥之后,把所有等式的答案乘起来就可以了。
Code
#include<iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<math.h> #define fo(i,a,b) for(i=a;i<=b;i++) #define fod(i,a,b) for(i=a;i>=b;i--) using namespace std; typedef long long ll; const int mo=1e9+7,maxn=2000007; int i,j,k,l,t,n,m; int c[maxn],d[maxn],ma[maxn],e[maxn],er[27],a[maxn],b[maxn],g[maxn]; ll ans,fact[maxn],ni[maxn],zong,o,p,ans1,q; int bz[maxn],num[maxn]; struct node{ int a,b,c; }w[maxn]; bool cmp(node x,node y){ return x.c<y.c; } ll qsm(ll x,ll y){ ll z=1; for(;y;y/=2,x=x*x%mo)if(y&1)z=z*x%mo; return z; } ll cc(ll x,ll y){return fact[x]*ni[y]%mo*ni[x-y]%mo;} int get(){ char ch=getchar();int x=0; while(ch<'0'||ch>'9')ch=getchar(); while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar(); return x; } void dfs(int x,int y,int z){ if (x>l+num[k]){ if(y&1)ans1=(ans1-cc(z+g[k]-1,g[k]-1)+mo)%mo; else ans1=(ans1+cc(z+g[k]-1,g[k]-1))%mo; return; } dfs(x+1,y,z); dfs(x+1,y+1,z-(w[x].b+1)); } int main(){ // freopen("equation.in","r",stdin); // freopen("equation.out","w",stdout); // freopen("fan.in","r",stdin); fact[0]=ni[0]=er[0]=1; fo(i,1,2000000)fact[i]=fact[i-1]*i%mo;ni[2000000]=qsm(fact[2000000],mo-2); fod(i,1999999,1)ni[i]=ni[i+1]*(i+1)%mo; fo(i,1,20)er[i]=er[i-1]*2; scanf("%d%d",&n,&m); zong=1; fo(i,1,m){ g[i]=get(); fo(j,1,g[i])a[j]=get(),bz[a[j]]=i; b[i]=get(); } scanf("%d",&t); fo(i,1,t)w[i].a=get(),w[i].b=get(),w[i].c=bz[w[i].a],num[w[i].c]++; sort(w+1,w+1+t,cmp); ans=1;l=0; fo(k,1,m){ ans1=0; dfs(l+1,0,b[k]); ans=(ll)ans*ans1%mo; l+=num[k]; } ans=(ans+mo)%mo; printf("%lld\n",ans); }
相关文章推荐
- 公钥和私钥
- 【Asp.Net】div和span元素的区别
- 在路上
- 软件本身是一个引导型消费.
- 即时通讯
- 2017.1.21夜间开车心得体会
- 如何保证矩阵计算的精确度:backward stable & well conditioned
- MFC—消息对话框
- GIT基本操作----新手特供
- c++builder还有个好处,可以直接添加pas到工程中,混合使用.
- JavaScript中this的指向问题
- Nginx源码阅读(模块)
- FileInputStream和FileReader的区别
- jenkins构建后邮件发送
- 移动web开发框架研究
- 测试代码块
- 机器学习实战之K近邻算法
- Leetcode——326. Power of Three
- 局域网访问本机的虚拟机项目(桥接方式最佳 )
- 堆