SCU4413 小粉刷匠(组合数学)

4413: 小粉刷匠

Submit your solution     Discuss this problem     Best solutions
 
id="main" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="500" src="http://cstest.scu.edu.cn/soj/problem/4413" style="height: 987px;">


链接:点击打开链接http://cstest.scu.edu.cn/soj/problem.action?id=4413 

题解:C(k,0)+C(k,1)+C(k,2)+...C(k,k)=2^k. 所以C(k,0)+C(k,2)+C(k,4)+...C(k,2*(k/2))=2^(k-1).

然后我们知道从k中取偶数个作为红,绿,就是后者,然后分别乘上偶数个作红绿,其他作黄蓝的组合数,这两个组合数公式可以合并,但是要注意处理C(k,0)的情况。要加上一半的2^K。

最后输出%lld才能AC。%I64d不能AC也是醉了。

#include <cstdio>  
#include <iostream>  
#include <cmath>  
#include <cstring>  
#include <algorithm>  
using namespace std;  
#define maxn 100010  
typedef long long LL;
LL m,n,p;  
LL Pow(LL a,LL b,LL mod){
    LL ans=1;  
    while(b){  
        if(b&1)  ans=(ans*a)%mod;  
        b>>=1;  
        a=(a*a)%mod;
    }  
    return ans;
}
int main(){
    int t;  
    scanf("%d",&t);  
    p=10007;
    LL k;
	while(t--){
		scanf("%lld",&k);
		LL ans=(Pow(2,2*k-2,p)+Pow(2,k-1,p))%p;
		printf("%lld\n",ans);
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值