zoukankan      html  css  js  c++  java
  • [2018 徐州 网络赛|Hard to prepare ] 环形染色问题的公式解法

    题目来源
    After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle.

    There are N guests Reimu serves. Kokoro has 2 k 2^k 2k
    masks numbered from 0 , 1 , ⋯   , 0 , 1 , ⋯ , 2 k − 1 0,1,cdots,0,1,⋯, 2^k - 1 0,1,,0,1,,2k1, and every guest wears one of the masks. The masks have dark power of Dark Nogaku, and to prevent guests from being hurt by the power, two guests seating aside must ensure that if their masks are numbered ii and j , then i XNOR j must be positive. (two guests can wear the same mask). XNOR means   ( i j ) ~(i^j)  (ij) and every number has kk bits. (1 XNOR 1 = 1, 0 XNOR 0 = 1, 1 XNOR 0 = 0)

    You may have seen 《A Summer Day’s dream》, a doujin Animation of Touhou Project. Things go like the anime, Suika activated her ability, and the feast will loop for infinite times. This really troubles Reimu: to not make her customers feel bored, she must prepare enough numbers of different Nogaku scenes. Reimu find that each time the same guest will seat on the same seat, and She just have to prepare a new scene for a specific mask distribution. Two distribution plans are considered different, if any guest wears different masks.

    In order to save faiths for Shrine, Reimu have to calculate that to make guests not bored, how many different Nogaku scenes does Reimu and Kokoro have to prepare. Due to the number may be too large, Reimu only want to get the answer modules 1 e 9 + 7 1e9+7 1e9+7 . Reimu did never attend Terakoya, so she doesn’t know how to calculate in module. So Reimu wishes you to help her figure out the answer, and she promises that after you succeed she will give you a balloon as a gift.

    Input
    First line one number TT , the number of testcases; ( T ≤ 20 T le 20 T20) .

    Next T lines each contains two numbers, N and k ( 0 < N , k ≤ 1 e 6 ) (0<N, k le 1e6) (0<N,k1e6) .

    Output
    For each testcase output one line with a single number of scenes Reimu and Kokoro have to prepare, the answer modules 1 e 9 + 7 1e9+7 1e9+7 .

    样例输入复制

    2
    3 1
    4 2
    

    样例输出复制

    2
    84
    

    题目来源
    ACM-ICPC 2018 徐州赛区网络预赛

    方法1:
    可参考

    #define Clear(x,val) memset(x,val,sizeof x)
    ll a[maxn];
    int n,k;
    void get() {
    	a[0] = 1;
    	for(int i=1; i<=1000000; i++) {
    		a[i] = (a[i-1] * 2) % mod;
    	}
    }
    ll dfs(ll now) {
    	if(now == 1) return a[k] % mod;
    	else if(now == 2) return (a[k] * (a[k] - 1)) % mod;
    	else {
    		ll cur = a[k] * qPow(a[k]-1,now-2) % mod;
    		cur = cur * (a[k] - 2) % mod;
    		return (cur + dfs(now - 2)) % mod;
    	}
    }
    int main() {
    //	cout << (2 ^ 1) << endl;
    //	cout << (~(0^1)) << endl;
    //	cout << (~(1^0)) << endl;
    //	cout << (~(1^1)) << endl;
    	get();
    	int _ = read;
    	while(_ --) {
    		n = read,k = read;
    		ll ans = dfs(n);
    		cout << ans % mod << endl;
    	}
    	return 0;
    }
    

    方法2:
    在这里插入图片描述
    图片来源

    	int _ = read;
    	while(_ --) {
    		n = read,k = read;
    		// ll ans = dfs(n);
    		// cout << ans % mod << endl;
    	    ll tot = qPow(2,k);
            ll ans = qPow(tot-1,n);
            if(n&1) ans += 1;
            else ans += tot - 1;
            cout << (ans + mod) % mod << endl;
        }
    
  • 相关阅读:
    iOS学习笔记10改用一些更新的API smallelephant_A
    iOS学习笔记2微博cell界面的实现 smallelephant_A
    iOS学习笔记12UISearchBar smallelephant_A
    iOS学习笔记8地图开发 smallelephant_A
    iOS学习笔记5GCD smallelephant_A
    ios学习笔记之1 通讯录应用练习 smallelephant_A
    iOS学习笔记11沙盒 smallelephant_A
    iOS学习笔记13字典数据写入plist smallelephant_A
    iOS学习笔记14sqlite数据库初探 smallelephant_A
    iOS学习笔记7NSURLSession smallelephant_A
  • 原文地址:https://www.cnblogs.com/PushyTao/p/15459781.html
Copyright © 2011-2022 走看看