# 洛谷P4260：[Code+#3]博弈论与概率统计 （组合数学+莫队/分块）

$ans=\sum _{i=0}^{m}\left({C}_{n+m}^{n+i}-{C}_{n+m}^{n+i+1}\right)\left(n-m+i\right)$

$ans=\left(n-m\right){C}_{n+m}^{n}+\sum _{i=0}^{m-1}{C}_{n+m}^{i}$

$ans=\sum _{i=0}^{n-1}{C}_{n+m}^{i}$

$F\left(n,k\right)=\sum _{i=0}^{k}{C}_{n}^{i}$

$F\left(n+1,k\right)=2F\left(n,k\right)-{C}_{n}^{k}$

CODE：

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<stdio.h>
#include<algorithm>
using namespace std;

const int maxn=250100;
const int NN=250000;
const int M=1000000007;
typedef long long LL;

struct data
{
int id,N,K;

LL fac[maxn];
LL nfac[maxn];

int ans[maxn];
int Div[maxn];
int t,n,m;
int sn=501;

void Preparation()
{
fac[0]=1;
for (LL i=1; i<=NN; i++) fac[i]=fac[i-1]*i%M;
nfac[0]=nfac[1]=1;
for (LL i=2; i<=NN; i++)
{
LL x=M/i,y=M%i;
nfac[i]=M-x*nfac[y]%M;
}
for (LL i=2; i<=NN; i++) nfac[i]=nfac[i-1]*nfac[i]%M;
}

int C(int nn,int mm)
{
if (mm>nn) return 0;
LL val=fac[nn];
val=val*nfac[mm]%M;
val=val*nfac[nn-mm]%M;
return val;
}

bool Comp(data x,data y)
{
int a=x.N/sn;
int b=y.N/sn;
return ( a<b || ( a==b && x.K<y.K ) );
}

int Mod(int x)
{
if (x>=M) return x-M;
else return x;
}

int Dec(int x)
{
if (x<0) return x+M;
else return x;
}

int main()
{
freopen("D.in","r",stdin);
freopen("D.out","w",stdout);

Preparation();
int p;
scanf("%d%d",&t,&p);
for (int i=1; i<=t; i++)
{
scanf("%d%d",&n,&m);
Div[i]=nfac[n+m];
Div[i]=(long long)Div[i]*fac[n]%M;
Div[i]=(long long)Div[i]*fac[m]%M;
}

int val=0;
for (int i=1; i<=t; i++)
{
{
val=0;
for (int i=0; i<=m; i++) val=Mod(val+ C(n,i) );
}
else
{
while (n>ask[i].N) --n,val=(long long)Mod(val+ C(n,m) )*nfac[2]%M;
}
ans[x]=Mod(ans[x]+val);
}

for (int i=1; i<=t; i++) ans[i]=(long long)ans[i]*Div[i]%M;
for (int i=1; i<=t; i++) printf("%d\n",ans[i]);
return 0;
}

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客