ProjectEuler237 Tours on a 4 x n playing board
思路是这样的
插头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的更多相关文章
- jquery开发的数字相加游戏(你能玩几分)
jquery开发的数字相加游戏,我在一轮中玩了632分(如下图),你能玩几分,哈哈... 我要试一试 下面贡献下这款“数字相加游戏”的开发过程. html部分: <div class=" ...
- Machine Learning and Data Mining(机器学习与数据挖掘)
Problems[show] Classification Clustering Regression Anomaly detection Association rules Reinforcemen ...
- (转) Playing FPS games with deep reinforcement learning
Playing FPS games with deep reinforcement learning 博文转自:https://blog.acolyer.org/2016/11/23/playing- ...
- Web Tours自带示例网站无法打开的解决方案
问题现象: LoadRunner自带的测试样品,旅行社机票预订系统HP Web Tours以下简称为Web Tours. 1.LoadRunner程序的Sample目录下无Web和Web Tours服 ...
- (转) Deep Reinforcement Learning: Playing a Racing Game
Byte Tank Posts Archive Deep Reinforcement Learning: Playing a Racing Game OCT 6TH, 2016 Agent playi ...
- Codeforces Round #184 (Div. 2) E. Playing with String(博弈)
题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...
- 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 ...
- URAL 1077 Travelling Tours(统计无向图中环的数目)
Travelling Tours Time limit: 1.0 secondMemory limit: 64 MB There are N cities numbered from 1 to N ( ...
- 论文笔记之:Playing for Data: Ground Truth from Computer Games
Playing for Data: Ground Truth from Computer Games ECCV 2016 Project Page:http://download.visinf.tu- ...
随机推荐
- go语言简单介绍,增强了解
1. Go语言没有类和继承的概念,所以它和 Java 或 C++ 看起来并不相同.但是它通过接口(interface)的概念来实现多态性.Go语言有一个清晰易懂的轻量级类型系统,在类型之间也没有层级之 ...
- idea查看源码没有注释的问题
进入idea的设置 勾选这两个 然后重新导入 页面的右上角有个下载download source的提示,点击下载即可 然后页面就要源码注释了
- Qt中mouseMoveEvent无效
最近用Qt软件界面,需要用到mouseMoveEvent,研究了下,发现些问题,分享一下. 在Qt中要捕捉鼠标移动事件需要重写MouseMoveEvent,但是MouseMoveEvent为了不太耗资 ...
- vue 页面 添加背景音乐
背景音乐 添加背景音乐 并有单击事件 循环播放 <template> <div id="page"> <div style="width ...
- centos7:ssh免密登陆设置及常见错误
目录 一.免密登录设置 二.常见错误 三.CentOS7再ssh-copy-id时的错误 一.免密登录设置 1.使用root用户登录,进入到目录/root/.ssh 2.执行命令:ssh-keygen ...
- SHA1签名工具类java
package com.net.util; import java.security.MessageDigest; import java.util.Iterator; import java.uti ...
- Django-报错信息及admin后台汉化
django-admin 汉化 效果对比 django admin 后台 报错信息 配置 修改配置文件中的 LANGUAGE_CODE 与 TIME_ZONE 即可. 将 django admin 后 ...
- 字典的setdefault()
setdefault(key, default) 函数 ---有key获取值.没key设置 key:default dict.setdefault(key, default=None) 如果 key ...
- 6.Linux查看哪个进程占用磁盘IO
$ iotop -oP命令的含义:只显示有I/O行为的进程
- Redis学习存档(2)——通过Java使用Redis:Jedis
一.创建项目,引入jedis jar包 可在百度搜索maven repository 进入后搜索jedis,复制依赖包到pom.xml文件中 <project xmlns="http: ...