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

最新文章

  1. Javascript 中的严格模式
  2. x01.Game.CubeRun: XACT3 播放声音
  3. []with[[]]
  4. js中的单体对象
  5. .net 中使用配置文件需注意引用dll文件
  6. windows对象分类
  7. STL之优先队列(priority_queue)
  8. 分支-03. 三天打鱼两天晒网-B3
  9. 搭建Ubuntu环境中的Error [dpkg 被中断,您必须手工运行 sudo dpkg --configure -a 解决此问题][安装Flashplayer出错 ]
  10. nyoj_16:矩形嵌套
  11. Spark算子--SortByKey
  12. setTimeout/setInterval,属性、连续动画、倒计时的分析
  13. ES容易忽视的集群配置
  14. postgresql总结
  15. 拦截器的使用,配置手机浏览器访问的h5页面
  16. gcc下inline的一个问题
  17. 机器学习英雄访谈录之 DL 自由职业者:Tuatini Godard
  18. SQL记录-PLSQL集合
  19. sublime text执行PHP代码
  20. 调试大叔V2.1.0(2018.12.17)|http/s接口调试、数据分析程序员辅助开发神器

热门文章

  1. Git学习笔记(一)Git初识及基本操作
  2. AngularJS入门之如何快速上手
  3. Shell编程进阶 2.2 shell数组
  4. Android中Activity之间的数据传递
  5. 【275】◀▶ Python 控制语句说明
  6. AudioManager 音量『转』
  7. css自动换行 word-break:break-all和word-wrap:break-word(转)
  8. php验证是否建立数据库,否,则自动建立
  9. C++输出斐波那契数列的几种方法
  10. 9.Delegate类