2016弱校联盟十一专场10.7(12点场)-D. Blocks
2016-10-07 16:00
375 查看
D. Blocks
Time Limit: 1000msCase Time Limit: 1000msMemory Limit: 65536KB64-bit integer IO format: %lld Java class name: MainSubmit StatusFont Size: + -Panda has received an assignment of painting a line of blocks. Since Panda is such an intelligent boy, he starts to think of a math problem of painting. Suppose there are N blocks in a line and each block can be paint red, blue,green or yellow. For some myterious reasons, Panda want both the number of red blocks and green blocks to be even numbers. Under such conditions, Panda wants to know the number of different ways to paint these blocks.Input
The first line of the input contains an integer T(1≤T≤100), the number of test cases.Each of the next T lines contains an integer N(1≤N≤10^9)indicating the number of blocks.Output
For each test cases, output the number of ways to paint the blocks in a single line. Since the answer may be quite large, you have to module it by 10007.Sample Input
2 1 2
Sample Output
2 6
挑战程序设计竞赛P202,上面是用矩阵的幂求的~
这里用组合数学的知识~
题目大意:一排砖,可以染成红,蓝,绿,黄四种颜色,要求红色和绿色的砖数均为偶数,求染色方法数
解题思路:如果不考虑要求,有4^n种方案,减去红奇绿偶,红偶绿奇,红奇绿奇。
设红绿砖数总和为k,则1<=k<=n;
第一种情况:k为奇数,则总数为2 * (c(k, 1) + c(k, 3) + c(k, 5) +……)* c(n, k) * 2^(n - k)第二种情况,k为偶数,则总数为(c(k,1) + c(k,3) + c(k, 5) +……)* c(n, k) * 2^(n - k) 所求总数为(2^(n-1))^2+(2^(n-1))#include<iostream>using namespace std;typedef long long LL;const LL mod=10007;LL pow(LL p,LL k){LL tmp=1;while(k){if(k&1){tmp=(tmp*p)%mod;k--;}k>>=1;p=(p*p)%mod;}return tmp;}int main(){LL T;cin>>T;LL n;LL ans;while(T--){cin>>n;ans=pow(2,n-1);ans=(ans*ans)%mod+ans;cout<<ans%mod<<endl;}return 0;}
相关文章推荐
- 2016弱校联盟十一专场10.7(12点场) E. Training little cats
- POJ 3735 Training little cats(矩阵乘法 + 稀疏矩阵优化)——2016弱校联盟十一专场10.7(12点场)
- [Contests]2016弱校联盟十一专场10.7
- 2016弱校联盟十一专场10.3(12点场)
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing
- 2016弱校联盟十一专场10.5(12点场) Increasing or Decreasing bnu 52325
- 2016弱校联盟十一专场10.7(12点场)-M. Subimage Recognition
- 2016弱校联盟十一专场10.3,BNU52308,大模拟
- 2016弱校联盟十一专场10.2 Longest Increasing Subsequence
- 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)
- 2016弱校联盟十一专场10.2——Around the World
- 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
- 2016弱校联盟十一专场10.2——Floyd-Warshall
- 2016弱校联盟十一专场10.5 I Increasing or Decreasing(数位dp)
- 2016弱校联盟十一专场10.5 F Fibonacci of Fibonacci(矩阵快速幂+找循环节)
- 2016弱校联盟十一专场10.5 F Fibonacci of Fibonacci(矩阵快速幂 + 循环节)
- [弱校联萌2016]2016弱校联盟十一专场10.3
- [弱校联萌2016]2016弱校联盟十一专场10.5
- 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)