\(\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. postgresql 模式与用户,及跨库访问

    1 控制台命令\h:查看SQL命令的解释,比如\h select.\?:查看psql命令列表.\l:列出所有数据库.\c [database_name]:连接其他数据库.\d:列出当前数据库的所有表格 ...

  2. Redis codis 搭建测试

    codis Codis 是一个分布式 Redis 解决方案, 对于上层的应用来说, 连接到 Codis Proxy 和连接原生的 Redis Server 没有明显的区别,有部分命令支持 Codis ...

  3. 侯捷STL学习(二)--序列容器测试

    第六节:容器之分类和各种测试(四) stack不提供iterator操作,破坏了容器的独特性,先进先出. 使用容器multiset(允许元素重复) 内部是红黑树,insert操作就保证了排好了序. 标 ...

  4. 2016.5.30实现透明Panel及控件置顶的方法

    想放置一个透明Panel在某控件上端,实现效果是可透过此Panel看见下面控件,但鼠标点击却无任何反应. 1.新建置自定义Panel类 using System; using System.Colle ...

  5. 如何创建和配置Solaris10 zones (ZT)

    http://thegeekdiary.com/how-to-create-and-configure-solaris-10-zones/ Solaris zones enables a softwa ...

  6. SqlServer——存储过程(未完工)

    http://www.cnblogs.com/blsong/archive/2009/11/30/1613534.html http://blog.csdn.net/lenotang/article/ ...

  7. 阿里云服务器ubuntu安装redis2.8.13

    阿里云服务器ubuntu安装redis2.8.13 2014-09-04 16:14 |  coding云 |  2198次阅读 | 暂无评论   一.下载redis 可以先下载到本地,然后ftp到服 ...

  8. apache 禁delete

    <VirtualHost *:80>ServerAdmin sunqz@jerei.comDocumentRoot /web/dasdf ServerName www.abc.com &l ...

  9. intellij idea 设置Live Template快速生成自定义代码块

    一.设置 类似于宏,话不多少,上步骤 File----->Setting 选择Live Template 新建触发规则 新建触发key 输入模版text 选择在哪个环境触发 选java 如果是其 ...

  10. Access restriction required library rt.jar

    在JAVA项目开发中,使用到了BASE64Decoder,但编辑运行时却会出现以下错误:Access restriction required library rt.jar,这里就详细的说明一下如何解 ...