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. BJOI2018爆零记

    没啥可说的 Day1 0分 T1 给你一个二进制串,每次修改一个位置,询问[l,r]区间中有多少二进制子串重排后能被3整除 T2 一个无向图(无重边自环)每个点有一个包含两种颜色的染色集合,一个边的两 ...

  2. 博客和GitHup链接地址

    硕哥博客链接:http://www.cnblogs.com/999-/p/6073601.html 硕哥GitHup链接:https://github.com/xiaodoufu

  3. ACM学习历程—HDU1028 Ignatius and the Princess III(递推 || 母函数)

    Description "Well, it seems the first problem is too easy. I will let you know how foolish you ...

  4. ubuntu下mysql的安装与配置

    1.安装,安装的过程中会提示你设置 MySql的"root"密码 sudo apt-get install mysql-server mysql-client 2.把  /etc/ ...

  5. 用idea工具对java打包:命令 mvn clear package,报错

    用idea工具对java打包:命令 mvn clear package,报错 网上都是eclipse的,要么是project structure和setting的(当然这俩也要用) 我都试了,每一个能 ...

  6. NancyFX 第一章 NancyFX 简介

    Nancy是.NET 平台的微框架.在受到Ruby社区的Sinatra框架启发下,NancyFx框架提供一个.NET平台下的低门槛.易上手的可用于Web开发工具包. 请注意我说的是可用于Web开发,这 ...

  7. Struts2&nbsp;+&nbsp;easyui的DataGrid&nbsp;分页

    jsp页面 js代码: $(function() { $('#ff').hide(); $('#tt').datagrid({ title : '信息显示', iconCls : 'icon-save ...

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

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

  9. apache配置中的小细节

    configuration error: couldn’t perform authentication错误的解决办法 configuration error: couldn’t perform au ...

  10. 30.构建单机多容器环境-故障&31.构建单机多容器环境

    主要的命令是docker run .主要是用它来构建容器 关机打开序列化 31.构建单机多容器环境 构建自己单机的多容器 加入我们做一个应用程序 -d是在后台运行,不会阻塞你的命令行 之前有一个空的a ...