思路是这样的

插头dp-->打表-->OEIS查表-->通项公式-->矩阵快速幂优化线性递推

OEIS竟然有这个东西的生成函数啊

答案为15836928

这是最终代码

#include <bits/stdc++.h>

using namespace std;

#define MOD 191981
#define mod 100000000
#define ll long long struct Matrix {
vector<vector<int> > a;
int n, m;
void init(int n, int m) {
this->n = n, this->m = m;
a.resize(n);
for(int i = 0; i < n; ++i) a[i].resize(m);
}
vector<int>& operator [](int index_x) {
return a[index_x];
}
friend Matrix operator * (Matrix lhs, Matrix rhs) {
Matrix c;
c.init(lhs.n, rhs.m);
for(int i = 0; i < lhs.n; ++i)
for(int j = 0; j < rhs.m; ++j)
for(int k = 0; k < lhs.m; ++k)
c[i][j] = (c[i][j]+1LL*lhs[i][k]*rhs[k][j]%mod)%mod;
return c;
}
}; Matrix eye(int n) {
Matrix c;
c.init(n, n);
for(int i = 0; i < n; ++i)
c[i][i] = 1;
return c;
} Matrix fpow(Matrix x, ll p) {
Matrix ret = eye(x.n);
while(p) {
if(p&1) ret = ret*x;
x = x*x;
p >>= 1;
}
return ret;
} //a(n) = 2*a(n-1) + 2*a(n-2) - 2*a(n-3) + a(n-4) int main() {
ll n;
scanf("%lld", &n);
if(n == 1) printf("1\n");
else if(n == 2) printf("1\n");
else if(n == 3) printf("4\n");
else if(n == 4) printf("8\n");
else {
Matrix m0, p, ans;
m0.init(4, 1);
m0[0][0] = 8, m0[1][0] = 4, m0[2][0] = 1, m0[3][0] = 1;
p.init(4, 4);
p[0][0] = 2, p[0][1] = 2, p[0][2] = -2, p[0][3] = p[1][0] = p[2][1] = p[3][2] = 1;
ans = fpow(p, n-4)*m0;
printf("%d\n", ans[0][0]);
}
return 0;
}

ProjectEuler237 Tours on a 4 x n playing board的更多相关文章

  1. jquery开发的数字相加游戏(你能玩几分)

    jquery开发的数字相加游戏,我在一轮中玩了632分(如下图),你能玩几分,哈哈... 我要试一试 下面贡献下这款“数字相加游戏”的开发过程. html部分: <div class=" ...

  2. Machine Learning and Data Mining(机器学习与数据挖掘)

    Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...

  3. (转) Playing FPS games with deep reinforcement learning

    Playing FPS games with deep reinforcement learning 博文转自:https://blog.acolyer.org/2016/11/23/playing- ...

  4. Web Tours自带示例网站无法打开的解决方案

    问题现象: LoadRunner自带的测试样品,旅行社机票预订系统HP Web Tours以下简称为Web Tours. 1.LoadRunner程序的Sample目录下无Web和Web Tours服 ...

  5. (转) Deep Reinforcement Learning: Playing a Racing Game

    Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...

  6. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

  7. ifrog-1028 Bob and Alice are playing numbers(trie树)

    题目链接: Bob and Alice are playing numbers DESCRIPTION Bob and his girl friend are playing game togethe ...

  8. URAL 1077 Travelling Tours(统计无向图中环的数目)

    Travelling Tours Time limit: 1.0 secondMemory limit: 64 MB There are N cities numbered from 1 to N ( ...

  9. 论文笔记之:Playing for Data: Ground Truth from Computer Games

    Playing for Data: Ground Truth from Computer Games ECCV 2016 Project Page:http://download.visinf.tu- ...

随机推荐

  1. NDK学习笔记-JNI多线程

    前面讲到记录到ffmpeg音视频解码的时候,采用的是在主线程中进行操作,这样是不行的,在学习了POSIX多线程操作以后,就可以实现其在子线程中解码了,也可以实现音视频同步了 简单示例 在native实 ...

  2. rest_framework之序列化组件

    什么是rest_framework序列化? 在写前后端不分离的项目时: 我们有form组件帮我们去做数据校验 我们有模板语法,从数据库取出的queryset对象不需要人为去转格式 当我们写前后端分离项 ...

  3. HashMap集合-遍历方法

    # HashMap集合-遍历方法 先定义好集合: public static void main(String[] args) { Map<String,String> onemap=ne ...

  4. 小菜鸟之crond

    前一天学习了 at 命令是针对仅运行一次的任务,循环运行的例行性计划任务,linux系统则是由 cron (crond) 这个系统服务来控制的.Linux 系统上面原本就有非常多的计划性工作,因此这个 ...

  5. windows10下无U盘安装ubuntu18 使用EasyUEFI(一点点体会)

    一.看BIOS 先看看自己电脑的是哪种启动模式  win+R 输入 msinfo32  查看自己电脑是哪种 (UEFI还是Legacy BIOS启动模式) 查看完之后  如果是UEFI的话 go on ...

  6. 基于TCP 协议的socket 简单通信

    DNS 服务器:域名解析 socket 套接字 : ​ socket 是处于应用层与传输层之间的抽象层,也是一组操作起来非常简单的接口(接受数据),此接口接受数据之后,交由操作系统 为什么存在 soc ...

  7. Django-djangorestframework-异常模块-源码及自定义异常

    目录 异常模块 为什么要自定义异常模块 常见的几种异常情况 异常模块源码分析 自定义 drf 异常处理 异常模块 为什么要自定义异常模块 所有经过 drf APIView 视图类产生的异常,都可以提供 ...

  8. pthread 编程基础

    Linux系统下的多线程遵循POSIX线程接口,称为pthread.编写Linux下的多线程程序,需要使用头文件pthread.h,连接时需要使用库libpthread.a.与vxworks上任务的概 ...

  9. idea的EasyCode使用

    EasyCode可以自动根据表格生成:entity,dao,service,serviceImpl,controller 使用方法: 一.安装EasyCode插件: File-setting-Plug ...

  10. 系统性能分析-vmstat命令详解

    最近温馨巩固Linux 操作系统的 vmstat命令,这个命令所能打印的系统信息满多的,比较好用,就顺当记录下重要的点,方便以后排查系统问题时拿出来用 字段 含义 procs 进程信息字段: -r:正 ...