BZOJ1856: [Scoi2010]字符串&&Luogu P1641 [SCOI2010]生成字符串

67 篇文章 1 订阅
17 篇文章 0 订阅

题目描述:

LG传送门
BZOJ传送门

题解:

这题看似有点像DP题,但是其实是一道排列组合题。答案就是C(n+m,m)-C(n+m,m-1)。
详细参考LG上xyz32768的题解
这里写图片描述
这里写图片描述

代码如下:

#include<cstdio>
#include<string>
using namespace std;
const int maxn=2000005,tt=20100403;
int n,m;
long long pow[maxn];
long long qsm(long long x,int y){
    long long ret=1,w=x;
    while (y) {
        if (y%2==1) ret=(ret*w)%tt;
        w=(w*w)%tt; y/=2;
    }
    return ret;
}
long long c(int x,int y,int z){
    return 1ll*(pow[x]*qsm(pow[y]*pow[z]%tt,tt-2))%tt;
}
int main(){
    scanf("%d %d",&n,&m);
    pow[0]=1ll;
    for (int i=1;i<=n+m;i++) pow[i]=(1ll*pow[i-1]*i)%tt;
    printf("%lld\n",(c(n+m,n,m)+tt-c(n+m,m-1,n+1))%tt);
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值