\(\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. Rails的静态资源管理(六)—— Asset Pipeline缓存存储方式、预处理、升级等

    官方文档:http://guides.ruby-china.org/asset_pipeline.html http://guides.rubyonrails.org/asset_pipeline.h ...

  2. 数据库:sql语句分别按日,按周,按月,按季统计金额

    如: 表:consume_record 字段:consume (money类型) date (datetime类型) 请问怎么写四条sql语句分别按日,按周,按月,按季统计消费总量. 如:1月 120 ...

  3. js生成邀请码(2)

    //生成邀请码方法一 /*function createInviteCode() { var s = [],a=6,b=10; var chars = "123456789QWERTYUIP ...

  4. linux下不用空格执行带参数的5种姿势

    在搞安全的时候经常会遇到代码/命令执行,不能用空格的情况,总结了几种的绕过方法. 1.!! [root@iZ28wg1kditZ tmp]# pwd /tmp [root@iZ28wg1kditZ t ...

  5. C Primer Plus学习笔记(三)- 字符串和格式化输入/输出

    从一个简单的例子开始 #include <stdio.h> int main() { char name[10]; printf("Input Your Name:\n" ...

  6. viewpagerindicator+UnderlinePageIndicator+ viewpage切换

    布局文件activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/androi ...

  7. 如何让DIALOG点击确定按钮之后由于数据不合法不关闭

    public void SetDialogIsClose(DialogInterface pDialog, Boolean pisClose) { try { Field _Field = pDial ...

  8. C#正则表达式匹配双引号

    html: <img class="bubble large" src="/images/hero-logos/cog.svg" width=" ...

  9. [hadoop入门]mapper与reducer(word_count计数demo)

    1.mapper #!/usr/bin/env python import sys for line in sys.stdin: line = line.strip() words = line.sp ...

  10. 04 UUID

    1 什么是UUID UUID 的目的是让分布式系统中的所有元素,都能有唯一的辨识资讯,而不需要透过中央控制端来做辨识资讯的指定. 2 应用场景 MySQL数据库不能想oracle数据库那样创建序列,就 ...