Wannafly挑战赛11_A_B_D

传送门

A.白兔的分身术

思路:看完题目第一反应p=n,k=1,直接交一发。提交过程中思考了一下,显然取p=n,k=1最优。

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
using namespace std;
int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    LL n; scanf("%lld",&n);
    printf("%lld\n",n+1);
    return 0;
}

B.白兔的式子

思路:其实我发现手推也很容易推出(实在不行就打表233),
f[n][m] = C(n-1,m-1)*a nm n − m *b m1 m − 1 ;
接下来问题就转变为求这三项的值的乘积,后两项非常容易,快速幂就行,对于前面C(n-1,m-1),可以用到费马小定理求组合数(只需要将r!和(n-r)!用逆元的方法就可以解决)
这里写图片描述

#include<bits/stdc++.h>
#define debug(a) cout << #a << " " << a << endl
#define LL long long
#define PI acos(-1.0)
#define eps 1e-6
const int N=1e5+7;
const LL mod =998244353;
using namespace std;
LL f[N];
LL my_pow(LL a,LL b)
{
    LL ans=1;
    while(b){
        if(b&1) ans=ans*a%mod;
        a=a*a%mod;
        b>>=1;
    }
    return ans;
}
LL inv(LL a,LL b)
{
    return my_pow(a,b-2);
}
LL C(LL n,LL m)
{
    return f[n]*inv(f[m],mod)%mod*inv(f[n-m],mod)%mod;
}
int main ()
{
    //yyy_3y
    //freopen("1.in","r",stdin);
    f[0]=1;
    for(int i=1;i<N;i++) f[i]=i*f[i-1]%mod;
    int T; scanf("%d",&T);
    for(int i=1;i<=T;i++){
        int a,b,n,m; scanf("%d%d%d%d",&a,&b,&n,&m);
        LL a1=my_pow(a,n-m);
        LL b1=my_pow(b,m-1);
        printf("%lld\n",C(n-1,m-1)*a1%mod*b1%mod);
    }
    return 0;

}

D—>bolg下一篇。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值