您的位置:首页 > 其它

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;}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: