第三天 B. Rubik‘s Cube Coloring (easy version)

11 篇文章 0 订阅
10 篇文章 0 订阅

It is the easy version of the problem. The difference is that in this version, there are no nodes with already chosen colors.

Theofanis is starving, and he wants to eat his favorite food, sheftalia. However, he should first finish his homework. Can you help him with this problem?

You have a perfect binary tree of 2k−1
nodes — a binary tree where all vertices i from 1 to 2k−1−1 have exactly two children: vertices 2i and 2i+1. Vertices from 2k−1 to 2k−1 don’t have any children. You want to color its vertices with the 6

Rubik’s cube colors (White, Green, Red, Blue, Orange and Yellow).

Let’s call a coloring good when all edges connect nodes with colors that are neighboring sides in the Rubik’s cube.

A picture of Rubik’s cube and its 2D map.

More formally:

a white node can not be neighboring with white and yellow nodes;
a yellow node can not be neighboring with white and yellow nodes;
a green node can not be neighboring with green and blue nodes;
a blue node can not be neighboring with green and blue nodes;
a red node can not be neighboring with red and orange nodes;
an orange node can not be neighboring with red and orange nodes; 

You want to calculate the number of the good colorings of the binary tree. Two colorings are considered different if at least one node is colored with a different color.

The answer may be too large, so output the answer modulo 109+7

.
Input

The first and only line contains the integers k
(1≤k≤60

) — the number of levels in the perfect binary tree you need to color.
Output

Print one integer — the number of the different colorings modulo 109+7
思路如下:这是一个完全二叉树,很容易就可以想到,除了根节点,所有的节点都是4种情况,根节点6种情况,所以就可以算出式子6*4^(n - 2)其中算平方利用了快速幂。
代码如下:

//快速幂
int fp(int base, int power) {
    int result = 1;
    while (power > 0) {
        if (power % 2 == 1) {
            result = result * base % mod;
        }
        power /= 2;
        base = (base * base) % mod;
    }
    return result;
}
 
signed main()
{
    int T = 1;
//    cin >> T;
    while(T --){
        int n; cin >> n;
        int node = 1;
        rep(i, 1, n){
            node *= 2;
        }
        node -= 2;
        cout << 6*fp(4, node)%mod;
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值