[POJ 3734] Blocks (矩阵快速幂、组合数学)
来源:互联网 发布:香港 知乎 编辑:程序博客网 时间:2024/05/17 03:42
http://blog.csdn.net/sio__five/article/details/37521491
Description
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
212
Sample Output
26
Source
/*ID: wuqi9395@126.comPROG:LANG: C++*/#include<map>#include<set>#include<queue>#include<stack>#include<cmath>#include<cstdio>#include<vector>#include<string>#include<fstream>#include<cstring>#include<ctype.h>#include<iostream>#include<algorithm>#define INF (1<<30)#define PI acos(-1.0)#define mem(a, b) memset(a, b, sizeof(a))#define For(i, n) for (int i = 0; i < n; i++)typedef long long ll;using namespace std;const int mod = 10007;int multi_pow(int a, int k, int mod) { int ans = 1; while(k) { if (k & 1) ans = (ans * a) % mod; k >>= 1; a = (a * a) % mod; } return ans;}int main () { int t, n; scanf("%d", &t); while(t--) { scanf("%d", &n); int ans = multi_pow(2, n - 1, mod); ans = (ans * ans) % mod + ans; printf("%d\n", ans % mod); } return 0;}
- [POJ 3734] Blocks (矩阵快速幂、组合数学)
- [POJ 3734] Blocks (矩阵快速幂、组合数学)
- poj 3734 Blocks(矩阵快速幂)
- poj #3734 Blocks(矩阵快速幂)
- POJ 3734 Blocks 组合数学
- poj 3734 Blocks 【矩阵快速幂】
- POJ 3734 Blocks(矩阵快速幂)
- POJ 3734 Blocks(矩阵快速幂)
- 【POJ 3734 Blocks】+ 矩阵快速幂
- POJ 3734 Blocks 矩阵快速幂
- poj 3734 Blocks【矩阵快速幂染色】
- poj 3734 Blocks(构造矩阵加快速幂)
- POJ 3734 Blocks(dp、矩阵快速幂)
- 【POJ 3734】Blocks(递推+矩阵快速幂)
- 文章标题 POJ 3734 : Blocks (矩阵快速幂)
- POJ 3734 Blocks 线性递推 矩阵快速幂
- Poj 3734 Blocks【矩阵快速幂+递推】
- Poj 3734 Blocks【递推+矩阵快速幂】好题
- 黑马程序员——Java基础---数据类型
- hdoj1022
- Unique Binary Search Trees
- Output result string after numbers addition and subtraction
- android之handle使用在消息机制使用
- [POJ 3734] Blocks (矩阵快速幂、组合数学)
- typedef的用法总结
- 【机房重构】——模板方法解决组合查询
- java 运行时异常 RuntimeException 和编译时异常的区别
- mysql导入导出csv
- 用Python写个简单的推荐系统(一)
- Swift与Objective-C与C++混编的问题
- apt-get error-------Reading package lists... Error!
- C语言基础:C语言指针(6) - 指针和字符串