\(\color{#0066ff}{题解}\)

然后a,b,c通过矩阵加速即可

为什么1出现偶数次3没出现的贡献是上面画绿线的部分呢?

考虑暴力统计这部分贡献,答案为\(\begin{aligned}\sum_{2|i}C_n^i*3^{n-i}\end{aligned}\)

显然如果没有\(\sum\)下面的限制,它就是一个生成函数\((x+3)^n\)

相当于我们只取偶数项

可以用单位根反演

把\(\omega_2^1,\omega_2^2\)分别代入\((x+3)^n\)

得到的就是2倍的和,然后再除以2,就是上面绿色部分

#include<bits/stdc++.h>
#define LL long long
LL in() {
char ch; LL x = 0, f = 1;
while(!isdigit(ch = getchar()))(ch == '-') && (f = -f);
for(x = ch ^ 48; isdigit(ch = getchar()); x = (x << 1) + (x << 3) + (ch ^ 48));
return x * f;
}
const int mod = 1e9 + 7;
const int maxn = 1e6 + 10;
struct node {
LL ju[3][3];
node(LL a = 0, LL b = 0, LL c = 0, LL d = 0, LL e = 0, LL f = 0, LL g = 0, LL h = 0, LL i = 0) {
ju[0][0] = a, ju[0][1] = b, ju[0][2] = c;
ju[1][0] = d, ju[1][1] = e, ju[1][2] = f;
ju[2][0] = g, ju[2][1] = h, ju[2][2] = i;
}
friend node operator * (const node &a, const node &b) {
node t;
for(int i = 0; i < 3; i++)
for(int j = 0; j < 3; j++)
for(int k = 0; k < 3; k++)
(t.ju[i][j] += a.ju[i][k] * b.ju[k][j] % mod) %= mod;
return t;
}
node ksm(LL b) {
node re(1, 0, 0, 0, 1, 0, 0, 0, 1);
node a = *this;
while(b) {
if(b & 1) re = re * a;
a = a * a;
b >>= 1;
}
return re;
}
};
LL ksm(LL x, LL y) {
LL re = 1LL;
while(y) {
if(y & 1) re = re * x % mod;
x = x * x % mod;
y >>= 1;
}
return re;
}
LL a[maxn], b[maxn], c[maxn], n;
int main() {
freopen("number.in", "r", stdin);
freopen("number.out", "w", stdout);
n = in();
node A(1), B(3, 1, 0, 2, 3, 2, 0, 1, 3);
A = A * B.ksm(n);
LL ans = A.ju[0][0];
(ans += ksm(3, n)) %= mod;
LL tot = (ksm(2, n - 1) + (ksm(4, n - 1) << 1LL)) % mod;
(tot <<= 1LL) %= mod;
ans = ((ans - tot) % mod + mod) % mod;
printf("%lld", ans);
return 0;
}

2019.2.25考试T1, 矩阵快速幂加速递推+单位根反演(容斥)的更多相关文章

  1. [bzoj1009](HNOI2008)GT考试 (kmp+矩阵快速幂加速递推)

    Description 阿 申准备报名参加GT考试,准考证号为N位数X1X2....Xn(0<=Xi<=9),他不希望准考证号上出现不吉利的数字.他的不吉利数学 A1A2...Am(0&l ...

  2. HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...

  3. CH 3401 - 石头游戏 - [矩阵快速幂加速递推]

    题目链接:传送门 描述石头游戏在一个 $n$ 行 $m$ 列 ($1 \le n,m \le 8$) 的网格上进行,每个格子对应一种操作序列,操作序列至多有 $10$ 种,分别用 $0 \sim 9$ ...

  4. HDU 1757 矩阵快速幂加速递推

    题意: 已知: 当x<10时:f(x)=x 否则:f(x) = a0 * f(x-1) + a1 * f(x-2) + a2 * f(x-3) + --+ a9 * f(x-10); 求:f(x ...

  5. 2019.2.26考试T2 矩阵快速幂加速DP

    \(\color{#0066ff}{题解 }\) 可以发现, 数据范围中的n特别小,容易想到状压 可以想到类似于状压DP的思路,按列进行转移 那么应该有3维,\(f[i][j][k]\)代表到第i列, ...

  6. CH3401 石头游戏(矩阵快速幂加速递推)

    题目链接:传送门 题目: 石头游戏 0x30「数学知识」例题 描述 石头游戏在一个 n 行 m 列 (≤n,m≤) 的网格上进行,每个格子对应一种操作序列,操作序列至多有10种,分别用0~9这10个数 ...

  7. 洛谷P1357 花园(状态压缩 + 矩阵快速幂加速递推)

    题目链接:传送门 题目: 题目描述 小L有一座环形花园,沿花园的顺时针方向,他把各个花圃编号为1~N(<=N<=^).他的环形花园每天都会换一个新花样,但他的花园都不外乎一个规则,任意相邻 ...

  8. HDU5950 Recursive sequence (矩阵快速幂加速递推) (2016ACM/ICPC亚洲赛区沈阳站 Problem C)

    题目链接:传送门 题目: Recursive sequence Time Limit: / MS (Java/Others) Memory Limit: / K (Java/Others) Total ...

  9. [bzoj1008](HNOI2008)越狱(矩阵快速幂加速递推)

    Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 In ...

随机推荐

  1. Redis 复制技术和高可用sentinel(哨兵模式)

    redis的复制技术和高可用(哨兵模式) 1 复制 为什么要复制 实现数据的多副本存储,从而可以实现服务的高可用 提供更好的读性能复制技术的关键点及难点 如何指定被复制对象 增量还是全量以及如何实现增 ...

  2. [0day]jQuery Mobile XSS

    漏洞影响范围: 任何一个website使用了 jQuery Mobile 并且开放了重定向都有可能存在XSS,并且目前还没有相关补丁信息. 应用介绍: jQuery Mobile是jQuery 框架的 ...

  3. 通过id查询出图片

    第一步,model中需要如下的做法 [UIHint("Picture")] //加上之后会默认显示上传图片的模式 public int PictrueId { get; set; ...

  4. jQuery-图片的放大镜显示效果(不需要大小图)

    问题:当页面高度很大时,放大图片的图层不会跟随着 1.demo.html ;display:none;}          #tip s   {position:absolute;top:40px;l ...

  5. ms project展开和折叠任务

    1.视图——大纲——显示子任务 2.视图——大纲——隐藏子任务

  6. [poj2449]Remmarguts' Date(K短路模板题,A*算法)

    解题关键:k短路模板题,A*算法解决. #include<cstdio> #include<cstring> #include<algorithm> #includ ...

  7. __tostring和__invoke 方法

    首先放上代码: <?php class MagicTest{ //__tostring会在把对象转换为string的时候自动调用 public function __tostring() { r ...

  8. C++面向对象类的实例题目十一

    题目描述: 写一个程序计算三角形,正方形和圆形3种图形的面积 程序代码: #include<iostream> #include<cmath> #define PAI 3.14 ...

  9. Opengl创建几何实体——四棱锥和立方体

    //#include <gl\glut.h>#include <GL\glut.h>#include <iostream> using namespace std; ...

  10. 仿射变换详解 warpAffine

    转自 http://www.cnblogs.com/dupuleng/articles/4055020.html 博客园 首页 新随笔 联系 管理 订阅 随笔- 1  文章- 185  评论- 14  ...