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 integerN(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 https://www.bnuoj.com/bnuoj/contest_show.php?cid=8507#problem/101988 一开始打表找规律,无果。
然后分析一下,开始的时候主要怕是2个红,然后绿色的可以4个,6个....这样分类很麻烦。
于是就转换思路。
枚举红色 + 绿色一共有多少个
枚举值就是0、2、4、6.....
我也会想到这样枚举会超时,但是先写公式出来,看看能不能化简,
每一次C(n, k)中,就是红色 + 绿色一共有k个,其中再枚举红色的个数,剩下的就会是绿色的个数了。
C(k, 0) + C(k, 2) + C(k, 4) .... 这个是标准的二项式系数奇次项的和。是2^(k - 1)
然后枚举红色 + 绿色一共有k个后,剩下的n - k个每个有两种选择,2^(n - k),于是一合并,就是2^(n - 1)
提取
2^(n - 1)
然后公式就出来了。

2^n + 2^(n - 1) * (2^(n - 1) - 1)
后面那个减1是因为没有2^0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string> int n;
LL ans = ;
int f[];
const int MOD = ;
void dfs(int cur) {
if (cur == n + ) {
int one = , tow = ;
for (int i = ; i <= n; ++i) {
one += f[i] == ;
tow += f[i] == ;
}
if (one % == && tow % == ) ans++;
// ans %= MOD;
return;
}
for (int i = ; i <= ; ++i) {
f[cur] = i;
dfs(cur + );
}
}
int quick_pow(int a, int b) {
int ans = ;
int base = a;
while (b) {
if (b & ) {
ans *= base;
if (ans >= MOD) ans %= MOD;
// ans %= MOD;
}
b >>= ;
base *= base;
if (base >= MOD) base %= MOD;
// base %= MOD;
}
return ans;
}
void work() {
// for (n = 1; n <=14; ++n) {
// ans = 0;
// dfs(1);
//// cout << ans % 10007 << endl;
// printf("n == %d %I64d\n", n, ans);
// }
int n;
scanf("%d", &n);
int ans = (quick_pow(, n) + (quick_pow(, n - ) * ((quick_pow(, n - ) + MOD - ) % MOD)) % MOD ) % MOD;
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt","r",stdin);
#endif
int t;
cin >> t;
while (t--) work();
return ;
}


D. Blocks 数学题的更多相关文章

  1. 从Script到Code Blocks、Code Behind到MVC、MVP、MVVM

    刚过去的周五(3-14)例行地主持了技术会议,主题正好是<UI层的设计模式——从Script.Code Behind到MVC.MVP.MVVM>,是前一天晚上才定的,中午花了半小时准备了下 ...

  2. 【POJ-1390】Blocks 区间DP

    Blocks Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5252   Accepted: 2165 Descriptio ...

  3. 开发该选择Blocks还是Delegates

    前文:网络上找了很多关于delegation和block的使用场景,发现没有很满意的解释,后来无意中在stablekernel找到了这篇文章,文中作者不仅仅是给出了解决方案,更值得我们深思的是作者独特 ...

  4. poj 1390 Blocks

    poj 1390 Blocks 题意 一排带有颜色的砖块,每一个可以消除相同颜色的砖块,,每一次可以到块数k的平方分数.问怎么消能使分数最大.. 题解 此题在徐源盛<对一类动态规划问题的研究&g ...

  5. Java 同步代码块 - Synchronized Blocks

    java锁实现原理: http://blog.csdn.net/endlu/article/details/51249156 The synchronized keyword can be used ...

  6. 区块 Blocks

    Structure / Blocks / Demonstrate block regions

  7. 使用Code::blocks在windows下写网络程序

    使用Code::blocks在windows下写网络程序 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创 ...

  8. Code::Blocks配置GTK+2和GTK+3

    Code::Blocks配置GTK+2和GTK+3 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创代码根 ...

  9. [翻译]理解Ruby中的blocks,Procs和lambda

    原文出处:Understanding Ruby Blocks, Procs and Lambdas blocks,Procs和lambda(在编程领域被称为闭包)是Ruby中很强大的特性,也是最容易引 ...

随机推荐

  1. 2018.3.3 How too much fructose may cause liver damage

    Fructose is the sweetest of the natural sugars. As its name suggests, it is found mainly in fruits. ...

  2. 书写优雅的shell脚本(八)- 日期格式化

    1. 将日期格式转为时间戳 获取当前时间:currenttime=`date "+%Y-%m-%d %H:%M:%S"` 结果:2015-04-13 11:15:43 将当前时间转 ...

  3. linux 进程学习笔记-进程退出/终止进程

    <!--[if !supportLists]-->Ÿ <!--[endif]-->退出/终止进程 void _exit(int status) 与 void exit(int ...

  4. 集训Day12

    快乐 快乐就完事了 今天把Trie树 / 可持久化Trie树搞了一下 Trie树可以维护区间最大异或和 具体就是区间异或和 -> 区间两个前缀异或和的异或 然后就变成了 "从n个数里找 ...

  5. BZOJ_3124_[Sdoi2013]直径_树形DP

    BZOJ_3124_[Sdoi2013]直径_树形DP Description 小Q最近学习了一些图论知识.根据课本,有如下定义.树:无回路且连通的无向图,每条边都有正整数的权值来表示其长度.如果一棵 ...

  6. SQL Server 将查询的结果生成insert语句

    1.将查询的结果插入到一张新表(yangTest 表系统会自动生成)select Area, District, RoadName, StationName, PathDirection, Stati ...

  7. sql web Admin 源码.net 升级

    http://www.cnblogs.com/foundation/archive/2008/10/07/1305297.html

  8. Process 启动参数问题

    c#在有些情况下需要在启动另一个程序时传递参数,这里存在两个问题. 1.如果在参数里面含有空格,那么传递过去就会变成一个字符数组,这种情况是不满足情况的,解决方案是在传递参数时将空格用一些特殊字符替换 ...

  9. IIS PHP的Loaded Configuration File为空解决[转]

    在Windows Server 2003上,IIS配置支持PHP,发现PHP扩展未加载,phpinfo()查看,显示 Configuration File (php.ini) Path (none) ...

  10. Spring入门第十三课

    通过FactoryBean来配置Bean package logan.spring.study.factoryBean; public class Car { private String brand ...