查找第n项在序列c ++

编程入门 行业动态 更新时间:2024-10-18 16:50:37
本文介绍了查找第n项在序列c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经找到了,你给出这种类型序列的问题:

I have found a problem in which you are given this type of sequence:

the first K terms : a1, a2, ... , ak; K coefficients : b1, b2, ... , bk

和复发:

S(i) = b1*S(i-K) + b2*S(i-K+1) + ... + bk*S(i-1).

我必须找出第n项。

I have to find out the Nth term.

我相信这个问题能够快速矩阵幂来解决,但我有困难时期发现我不得不使用矩阵。我想用C ++的问题。任何人都可以给我一些提示有关我应该如何处理这类问题?

I believe this problem can be solved with fast matrix exponentiation but I am having hard time discovering the matrices I have to use. I am trying to write the problem in C++. Can anyone give me some hints about how should I treat this type of problem?

推荐答案

作为一个无耻的自我推销,我codeD起来的一个程序来解决使用矩阵乘法的线性复发。在该文件的顶部的注释描述什么要形成基质是,以及如何使用重复平方算法来有效地计算复发的第n项

As a shameless self-promotion, I coded up a program to solve linear recurrences using matrix multiplication. The comments at the top of the file describe what the matrix you want to form is, as well as how to use the repeated squaring algorithm to efficiently compute the nth term of the recurrence.

希望这有助于!

更多推荐

查找第n项在序列c ++

本文发布于:2023-11-30 04:29:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648729.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:序列

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!