ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

[2018 徐州 网络赛|Hard to prepare ] 环形染色问题的公式解法

2021-10-08 23:59:29  阅读:234  来源: 互联网

标签:XNOR prepare Reimu read ll Hard 2018 now mod


题目来源
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,⋯,2k−1, 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 T≤20) .

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

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;
    }

标签:XNOR,prepare,Reimu,read,ll,Hard,2018,now,mod
来源: https://blog.csdn.net/weixin_45712255/article/details/120662130

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有