D. TediousLee

time limit per test2 seconds memory limit per test256 megabytes
inputstandard input outputstandard 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 n as a rooted tree
constructed as described below.

A rooted dead bush of level 1 is a single vertex. To construct an RDB
of level i we, at first, construct an RDB of level i−1, then for each
vertex u:

if u has no children then we will add a single child to it; if u has
one child then we will add two children to it; if u has more than one
child, then we will skip it. Rooted Dead Bushes of level 1, 2 and 3.
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 1. Lee has a Rooted
Dead Bush of level n. 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+7.

Input The first line contains one integer t (1≤t≤104) — the number of
test cases.

Next t lines contain test cases — one per line.

The first line of each test case contains one integer n (1≤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+7.

Example inputCopy 7 1 2 3 4 5 100 2000000 outputCopy 0 0 4 4 12
990998587 804665184 Note It’s easy to see that the answer for RDB of
level 1 or 2 is 0.

The answer for RDB of level 3 is 4 since there is only one claw we can
choose: {1,2,3,4}.

The answer for RDB of level 4 is 4 since we can choose either single
claw {1,3,2,4} or single claw {2,7,5,6}. There are no other claws in
the RDB of level 4 (for example, we can’t choose {2,1,7,6}, since 1 is
not a child of center vertex 2).

Rooted Dead Bush of level 4.

构造的方法:
1 2 3的图
在这里插入图片描述

4的情况
在这里插入图片描述

一个"claw" 计数单位
在这里插入图片描述

仔细观察这个图,每次节点都会向下生长一个,如果向下生长过了,就向左右各生长一个,向左右长过之后这个节点就可以被涂色了。
可以注意到,每个节点需要两个回合才能生成一个claw,且每个分支都会不断延申下去。
结合上面的两个条件,就可以知道数目cnt[i]=cnt[i-1]+2*cnt[i-2]
但是有时候1-2-3-4这几个数字并没有被计算在内。
可以发现,每递进3层,就会出现这样的情况。
那么就逢3进1

//cyc
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define vector<int> VI
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define per(i,a,n) for(int i=n;i>=a;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mst(a) memset(a,0,sizeof a)
#define int long long

using namespace std;
typedef pair<int,int> pii;
const int maxn=2e6+5;
const int mod=1e9+7;
int a[maxn];
int root_val[maxn];

signed main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int _;
    cin>>_;
    for(int i=3;i<maxn;i++){
        a[i]=a[i-1]+2*a[i-2];
        if(!root_val[i-1]&&!root_val[i-2]){
            a[i]++;
            root_val[i]=1;
        }
        a[i]%=mod;
    }
    while(_--){
        int p;
        cin>>p;
        cout<<a[p]*4%mod<<endl;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值