[bzoj1004] Cards

  • 题意(原题):
  • 一些卡片,染成三种不同的颜色,分别sr,sb,sg张。给出m种洗牌方法,求有多少染色方案。如果一种染色方案能通过某种洗牌方法变成另一种方案,这两种方案相同。保证任意多次洗牌都可用洗牌方法中的一种代替,且对每种洗牌法,都存在一种洗牌法使得能回到原状态。
  • 思路:
  • 这儿写的非常好,我认为我没必要再写一个。其中关于逆元的可以参考我的这篇文章。
  • 代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#define LL long long 
using namespace std;
LL ans=1,sr,sb,sg,n,m,p;
LL power(LL a,LL b)
{
    LL ans=1;
    while(b)
    {
        if(b&1)ans=ans*a%p;
        a=a*a%p;b/=2;
    }
    return ans;
}
int main()
{
    scanf("%lld %lld %lld %lld %lld",&sr,&sb,&sg,&m,&p);n=sr+sb+sg;
    LL t=1;for(LL i=1;i<=sr;i++)t=t*(n-i+1)/i;ans=ans*(t%p)%p;
    t=1;n-=sr;for(LL i=1;i<=sg;i++)t=t*(n-i+1)/i;ans=ans*(t%p)%p;
    ans=(ans*power(m+1,p-2))%p;printf("%lld\n",ans);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值