ACM-ICPC 2018 焦作赛区网络预赛 L. Poor God Water

传送门:https://nanti.jisuanke.com/t/31721

God Water likes to eat meat, fish and chocolate very much, but unfortunately, the doctor tells him that some sequence of eating will make them poisonous.

Every hour, God Water will eat one kind of food among meat, fish and chocolate. If there are 33 continuous hours when he eats only one kind of food, he will be unhappy. Besides, if there are 33 continuous hours when he eats all kinds of those, with chocolate at the middle hour, it will be dangerous. Moreover, if there are 33 continuous hours when he eats meat or fish at the middle hour, with chocolate at other two hours, it will also be dangerous.

Now, you are the doctor. Can you find out how many different kinds of diet that can make God Water happy and safe during NN hours? Two kinds of diet are considered the same if they share the same kind of food at the same hour. The answer may be very large, so you only need to give out the answer module 10000000071000000007.

Input

The fist line puts an integer TT that shows the number of test cases. (T \le 1000T≤1000)

Each of the next TT lines contains an integer NN that shows the number of hours. (1 \le N \le 10^{10}1≤N≤1010)

Output

For each test case, output a single line containing the answer.

样例输入复制

3
3
4
15

样例输出复制

20
46
435170

题目来源

ACM-ICPC 2018 焦作赛区网络预赛

题意:这个同学吃abc三种食物,一天吃一个,连续三天的以下情况他会中毒1.aaa bbb ccc相同类型连吃三天 2.acb bca三种都吃而且c在中间 3.cac cbc  c在两边 求n天几种吃的方案

思路:暴力dfs打表了十来天,

3      20
4      46
5      106
6      244
7      560
8      1286
9      2956
10      6794
11      15610
12      35866
13      82416
14      189384
15      435170
16      999936
17      2297686

看了看ac率感觉是个线性的关系,于是十分暴力地……

#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<string>
#include<iostream>
#include<map>
#include<vector>
#include<set>
#include<queue>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

int a[]={3,9,20,46,106,244,560,1286,2956,6794,15610};

int main()
{
	int b=20;
	for(int i=-b;i<=b;i++)
	{
		for(int j=-b;j<=b;j++)
		{
			for(int k=-b;k<=b;k++)
			{
				for(int l=-b;l<=b;l++){
					for(int q=-b;q<=b;q++){
						int c[7]={0};
						for(int w=0;w<=5;w++)
						{
							int ans=0;
							ans=a[w]*i+a[w+1]*j+a[w+2]*k+a[w+3]*l+a[w+4]*q;
							c[w]=ans;
							
						}
						if(c[0]==a[5]&&c[1]==a[6]&&c[2]==a[7]&&c[3]==a[8]&&c[4]==a[9]&&c[5]==a[10])
						{
							printf("%d %d %d %d %d\n",i,j,k,l,q);
						}
					}
				}
			}
		}
	}
	return 0;
}

wow只有一组!那么不如……

#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
#define inf 0x3f3f3f3f
typedef long long LL;

const LL SMod = 1000000007;
struct Matrix
{
	LL m[4][4];
};

Matrix Mul(Matrix a, Matrix b)
{
	Matrix c;
	memset(c.m, 0, sizeof(c.m));
	for (int i = 0; i<4; i++)
		for (int j = 0; j<4; j++)
			for (int k = 0; k<4; k++)
				c.m[i][j] = (c.m[i][j] + (a.m[i][k] * b.m[k][j]) % SMod ) % SMod;
	return c;
}

Matrix fastm(Matrix a, LL n)
{
	Matrix res;
	memset(res.m, 0, sizeof(res.m));
	res.m[0][0] = res.m[1][1] = res.m[2][2] = res.m[3][3]= 1;
	while (n)
	{
		if (n & 1)
			res = Mul(res, a);
		n >>= 1;
		a = Mul(a, a);
	}
	return res;
}

int main()
{
	LL n;
	Matrix chu;
	chu.m[0][0] = 2, chu.m[0][1] = -1, chu.m[0][2] = 3, chu.m[0][3] = 2;
	chu.m[1][0] = 1, chu.m[1][1] = 0, chu.m[1][2] = 0, chu.m[1][3] = 0;
	chu.m[2][0] = 0, chu.m[2][1] = 1, chu.m[2][2] = 0, chu.m[2][3] = 0;
	chu.m[3][0] = 0, chu.m[3][1] = 0, chu.m[3][2] = 1, chu.m[3][3] = 0;
	int T;
	scanf("%d", &T);
	while (T--)
	{
		scanf("%lld", &n);
		if (n == 1)printf("3\n");
		else if (n == 2)printf("9\n");
		else if (n == 3)printf("20\n");
		else if (n == 4)printf("46\n");
		else if (n == 5)printf("106\n");
		else
		{
			n -= 5;
			Matrix tt = fastm(chu, n);
			LL ans = 0;
			ans = ans + tt.m[0][0] * 106; ans %= SMod;
			ans = ans + tt.m[0][1] * 46; ans %= SMod;
			ans = ans + tt.m[0][2] * 20; ans %= SMod;
			ans = ans + tt.m[0][3] * 9; ans %= SMod;
			printf("%lld\n", ans);
		}
	}

}

妙鸭过了!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值