【组合数学】HDU5698[瞬间移动]题解

题目概述

刚开始你在 (1,1) ,每次能够瞬间移动到右下任意一个格子(如下图),求到 (n,m) 的方案数。

img

解题报告

组合数很多性质我不知道啊QAQ,做到题目慢慢补吧。

i=0nCinCim=Cnn+m(nm)

证明:二项式定理: (a+b)n akbnk 的系数为 Ckn

那么 (a+b)n+m anbm 的系数为 Cnn+m

(a+b)n(a+n)m anbm 的系数为 ni=0CinCmim=ni=0CinCim

因为 (a+b)n(a+b)m=(a+b)n+m ,所以 ni=0CinCim=Cnn+m(nm)

=====我是分割线QwQ=====

枚举步数 i ,我们可以把行列分开来考虑,那么就可以这么理解:有 n2 个球和 i 个盒子,求每个盒子至少一个球的方案数;有 m2 个球和 i 个盒子,求每个盒子至少一个球的方案数。

这就变成了经典的盒子问题,假设 nm ,那么总方案数为: n2i=0CinCim

然后用上面说的公式就行了,答案为 Cn2n+m4

示例程序

#include<cstdio>
using namespace std;
typedef long long LL;
const int maxn=200000,MOD=1000000007;

int n,m,fac[maxn+5],INV[maxn+5];

bool Eoln(char ch) {return ch==10||ch==13||ch==EOF;}
char readc()
{
    static char buf[100000],*l=buf,*r=buf;
    if (l==r) r=(l=buf)+fread(buf,1,100000,stdin);
    if (l==r) return EOF; else return *l++;
}
int readi(int &x)
{
    int tot=0,f=1;char ch=readc(),lst=ch;
    while ('9'<ch||ch<'0') {if (ch==EOF) return EOF;lst=ch;ch=readc();}
    if (lst=='-') f=-f;
    while ('0'<=ch&&ch<='9') tot=(tot<<3)+(tot<<1)+ch-48,ch=readc();
    return x=tot*f,Eoln(ch);
}
void Make()
{
    fac[0]=INV[0]=INV[1]=1;
    for (int i=1;i<=maxn;i++) fac[i]=(LL)fac[i-1]*i%MOD;
    for (int i=2;i<=maxn;i++) INV[i]=MOD-(LL)INV[MOD%i]*(MOD/i)%MOD;
    for (int i=2;i<=maxn;i++) INV[i]=(LL)INV[i]*INV[i-1]%MOD;
}
inline int C(int x,int y) {return (LL)fac[x]*INV[y]%MOD*INV[x-y]%MOD;}
int main()
{
    freopen("program.in","r",stdin);
    freopen("program.out","w",stdout);
    Make();while (readi(n),readi(m)!=EOF) printf("%d\n",C(n+m-4,n-2));
    return 0;
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值