https://www.cnblogs.com/zzqsblog/p/6877339.html

https://blog.csdn.net/qq_39972971/article/details/80725873

#include <bits/stdc++.h>

using namespace std;

typedef long long LL;

const int N = 3005;
const int MOD = 1E9 + 7; inline int Add(int a, int b) {
return (a + b >= MOD) ? (a + b - MOD) : (a + b);
}
inline int Sub(int a, int b) {
return (a >= b) ? (a - b) : (a - b + MOD);
}
inline int Mul(int a, int b) {
return (LL)a * b % MOD;
}
inline int Pow(int a, int b) {
int c = 1;
for (; b; a = Mul(a, a), b >>= 1)
if (b & 1) c = Mul(c, a);
return c;
} int n;
int a[N], b[N], c[N], d[N]; int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i)
scanf("%d", &a[i]);
int m = 0, fa = 0, dt = 0, k = 0;
for (int i = 1; i <= n; ++i) {
int t = a[i];
for (int j = 1; j <= m; ++j)
t = Sub(t, Mul(b[j], a[i - j]));
if (!t) continue;
if (!fa) {
k = m;
m = i;
fa = i;
dt = t;
continue;
}
copy(b + 1, b + m + 1, d + 1);
int x = i - 1 - fa, v = Mul(t, Pow(dt, MOD - 2)), nm = max(m, x + k + 1);
b[x + 1] = Add(b[x + 1], v);
for (int j = 1; j <= k; ++j)
b[x + j + 1] = Sub(b[x + j + 1], Mul(c[j], v));
if (i - m > fa - k) {
copy(d + 1, d + m + 1, c + 1);
fa = i;
dt = t;
k = m;
}
m = nm;
}
// for (int i = m + 1; i <= n; ++i) {
// int t = a[i];
// for (int j = 1; j <= m; ++j)
// t = Sub(t, Mul(a[i - j], b[j]));
// if (t) {
// cerr << i << endl;
// throw;
// }
// }
printf("%d\n", m);
for (int i = 1; i <= m; ++i)
printf("%d ", b[i]);
puts("");
return 0;
}

Berlekamp-Massey algorithm的更多相关文章

  1. Berlekamp Massey算法求线性递推式

    BM算法求求线性递推式   P5487 线性递推+BM算法   待AC.   Poor God Water   // 题目来源:ACM-ICPC 2018 焦作赛区网络预赛 题意   God Wate ...

  2. 【hdu 6172】Array Challenge(数列、找规律)

    多校10 1002 HDU 6172 Array Challenge 题意 There's an array that is generated by following rule. \(h_0=2, ...

  3. 线性齐次递推式快速求第n项 学习笔记

    定义 若数列 \(\{a_i\}\) 满足 \(a_n=\sum_{i=1}^kf_i \times a_{n-i}\) ,则该数列为 k 阶齐次线性递推数列 可以利用多项式的知识做到 \(O(k\l ...

  4. Factorization

    Factorization or factoring consists of writing a number or another mathematical object as a product ...

  5. 挑子学习笔记:两步聚类算法(TwoStep Cluster Algorithm)——改进的BIRCH算法

    转载请标明出处:http://www.cnblogs.com/tiaozistudy/p/twostep_cluster_algorithm.html 两步聚类算法是在SPSS Modeler中使用的 ...

  6. PE Checksum Algorithm的较简实现

    这篇BLOG是我很早以前写的,因为现在搬移到CNBLOGS了,经过整理后重新发出来. 工作之前的几年一直都在搞计算机安全/病毒相关的东西(纯学习,不作恶),其中PE文件格式是必须知识.有些PE文件,比 ...

  7. [异常解决] windows用SSH和linux同步文件&linux开启SSH&ssh client 报 algorithm negotiation failed的解决方法之一

    1.安装.配置与启动 SSH分客户端openssh-client和openssh-server 如果你只是想登陆别的机器的SSH只需要安装openssh-client(ubuntu有默认安装,如果没有 ...

  8. [Algorithm] 使用SimHash进行海量文本去重

    在之前的两篇博文分别介绍了常用的hash方法([Data Structure & Algorithm] Hash那点事儿)以及局部敏感hash算法([Algorithm] 局部敏感哈希算法(L ...

  9. Backtracking algorithm: rat in maze

    Sept. 10, 2015 Study again the back tracking algorithm using recursive solution, rat in maze, a clas ...

  10. [Algorithm & NLP] 文本深度表示模型——word2vec&doc2vec词向量模型

    深度学习掀开了机器学习的新篇章,目前深度学习应用于图像和语音已经产生了突破性的研究进展.深度学习一直被人们推崇为一种类似于人脑结构的人工智能算法,那为什么深度学习在语义分析领域仍然没有实质性的进展呢? ...

随机推荐

  1. jquery.validate.js使用之自定义表单验证规则

    jquery.validate.js使用之自定义表单验证规则,下面列出了一些常用的验证法规则 jquery.validate.js演示查看 jquery validate强大的jquery表单验证插件 ...

  2. 报错:Original error: Could not proxy command to remote server. Original error: Error: read ECONNRESET

    问题:Appium的android真机启动手机时,会遇到以下问题: An unknown server-side error occurred while processing the command ...

  3. Oracle自动性能统计

    Oracle自动性能统计   高效诊断性能问题,需要提供完整可用的统计信息,好比医生给病人看病的望闻问切,才能够正确的确诊,然后再开出相应的药方.Oracle数据库为系统.会话以及单独的sql语句生成 ...

  4. ElasticSearch的中文分词器ik

    一.前言   为什么要在elasticsearch中要使用ik这样的中文分词呢,那是因为es提供的分词是英文分词,对于中文的分词就做的非常不好了,因此我们需要一个中文分词器来用于搜索和使用. 二.IK ...

  5. TensorFlow学习笔记0-安装TensorFlow环境

    TensorFlow学习笔记0-安装TensorFlow环境 作者: YunYuan 转载请注明来源,谢谢! 写在前面 系统: Windows Enterprise 10 x64 CPU:Intel( ...

  6. 模版include的用法

    from flask import Flask,render_template app = Flask(__name__) @app.route('/') def hello_world(): ret ...

  7. tableau分布式添加节点

    参考: 两节点的安装:https://zhuanlan.zhihu.com/p/44732932https://help.tableau.com/current/server-linux/zh-cn/ ...

  8. Solrcloud+tomcat+zookeeper

    准备两台服务器,目录结构如下 主机名 IP地址 tomcat安装路径 zookeeper安装路径 solr安装路径 java安装路径 sht-sgmhadoopnn-01 172.16.101.55 ...

  9. spring配置添加多个事务(转)

    大多数项目只需要一个事务管理器.然而,有些项目为了提高效率.或者有多个完全不同又不相干的数据源,最好用多个事务管理器.机智的Spring的Transactional管理已经考虑到了这一点,首先分别定义 ...

  10. python中判断变量的类型

    python的数据类型有:数字(int).浮点(float).字符串(str),列表(list).元组(tuple).字典(dict).集合(set) 一般通过以下方法进行判断: 1.isinstan ...