SCU4413 小粉刷匠(组合数学)

来源:互联网 发布:ug钻孔编程 编辑:程序博客网 时间:2024/04/29 03:55

4413: 小粉刷匠

Submit your solution     Discuss this problem     Best solutions 


链接:点击打开链接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;}


0 0