D. TediousLee
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
Lee tried so hard to make a good div.2 D problem to balance his recent contest, but it still doesn't feel good at all. Lee invented it so tediously slow that he managed to develop a phobia about div.2 D problem setting instead. And now he is hiding behind the bushes...
Let's define a Rooted Dead Bush (RDB) of level nn as a rooted tree constructed as described below.
A rooted dead bush of level 11 is a single vertex. To construct an RDB of level ii we, at first, construct an RDB of level i−1i−1, then for each vertex uu:
- if uu has no children then we will add a single child to it;
- if uu has one child then we will add two children to it;
- if uu has more than one child, then we will skip it.
Rooted Dead Bushes of level 11, 22 and 33.
Let's define a claw as a rooted tree with four vertices: one root vertex (called also as center) with three children. It looks like a claw:
The center of the claw is the vertex with label 11.
Lee has a Rooted Dead Bush of level nn. Initially, all vertices of his RDB are green.
In one move, he can choose a claw in his RDB, if all vertices in the claw are green and all vertices of the claw are children of its center, then he colors the claw's vertices in yellow.
He'd like to know the maximum number of yellow vertices he can achieve. Since the answer might be very large, print it modulo 109+7109+7.
Input
The first line contains one integer tt (1≤t≤1041≤t≤104) — the number of test cases.
Next tt lines contain test cases — one per line.
The first line of each test case contains one integer nn (1≤n≤2⋅1061≤n≤2⋅106) — the level of Lee's RDB.
Output
For each test case, print a single integer — the maximum number of yellow vertices Lee can make modulo 109+7109+7.
Example
input
Copy
7 1 2 3 4 5 100 2000000
output
Copy
0 0 4 4 12 990998587 804665184
Note
It's easy to see that the answer for RDB of level 11 or 22 is 00.
The answer for RDB of level 33 is 44 since there is only one claw we can choose: {1,2,3,4}{1,2,3,4}.
The answer for RDB of level 44 is 44 since we can choose either single claw {1,3,2,4}{1,3,2,4} or single claw {2,7,5,6}{2,7,5,6}. There are no other claws in the RDB of level 44 (for example, we can't choose {2,1,7,6}{2,1,7,6}, since 11 is not a child of center vertex 22).
Rooted Dead Bush of level 4.
题意:求爪子的数量 * 4,也就是染色的数量
什么是爪子呢
这就是一个爪子
题目输入的是层数
以下是推出的两个公式
dp[i][1]是到第i层的染色结果数量
dp[i][0]是第i层新增的叶子结点个数
由于长成一个爪子需要的周期是2层 所以结论就是
第i层染色总数 = i - 2层新增节点数 * 4 + i - 3层 总染色数
大概推一下就能得到
然后就是代码 记得mod
#include<bits/stdc++.h>
#define ll long long
const int maxn = 2e6 + 5;
const int mod = 1e9 + 7;
using namespace std;
ll dp[maxn][2];
void solve(){
int n;
cin >> n;
cout << a[n][1] << endl;
}
void init(){
dp[1][1] = 0;
dp[1][0] = 1;
dp[2][1] = 0;
dp[2][0] = 1;
dp[3][1] = 4;
dp[3][0] = 3;
for(int i = 4; i <= 2e6; i++){
dp[i][0] = (dp[i - 2][0] * 2 + dp[i - 1][0]) % mod;
dp[i][1] = (dp[i - 3][1] + dp[i - 2][0] * 4) % mod;
//cout << i << " " << a[i][1] << endl;
}
}
int main(){
init();
int t;
cin >> t;
while(t--){
solve();
}
}