当前位置:网站首页>On Lagrange interpolation and its application
On Lagrange interpolation and its application
2022-07-03 16:46:00 【Ouye xjx】
Preface
I've been doing for many years NOI The original title is , And then it did [NOI2019] robot , I was surprised to find that I didn't learn Lagrange interpolation !
There was an inserted question in the previous provincial topic ([ Provincial election joint examination 2022] Tree filling ), But in O n e I n D a r k \rm O\red{neInDark} OneInDark Sterling inversion is used under the recommendation of . Actually, pulling and inserting is very simple , And it is more suitable to do things like filling trees 、 Robots are like this DP Optimize the topic .
brief introduction
Stick to others
In numerical analysis , Lagrange interpolation is based on French 18 Century mathematician Joseph · A polynomial interpolation method named by Lagrange . If you observe a physical quantity in practice , The corresponding observations are obtained in several different places , Lagrange interpolation can find a polynomial , It just takes the observed value at each observation point . The above polynomial is called Lagrange ( interpolation ) polynomial .
Lagrange interpolation
as everyone knows , Give a n n n Polynomial of degree n + 1 n+1 n+1 A point value can uniquely find this polynomial , A simple solution is to list n + 1 n+1 n+1 Equation and then use Gauss elimination , Complexity O ( n 3 ) O(n^3) O(n3), It is often accompanied by the problem of accuracy .
Lagrange interpolation can be used in O ( n 2 ) O(n^2) O(n2) Find the polynomial with enough accuracy in time .
Directly up Lagrange interpolation formula :
f ( x ) = ∑ i = 0 n y i ∏ j ≠ i x − x j x i − x j f(x)=\sum_{i=0}^ny_i\prod_{j\neq i}\frac{x-x_j}{x_i-x_j} f(x)=i=0∑nyij=i∏xi−xjx−xj This formula is very clever , Because you can find that it can just get all the point values , And the maximum number is n n n.
Using this formula to directly find polynomials is also O ( n 3 ) O(n^3) O(n3)( It's slower than high consumption ), But it can be optimized !
We can find out g ( x ) = ∏ i = 0 n ( x − x i ) g(x)=\prod_{i=0}^n(x-x_i) g(x)=∏i=0n(x−xi), Then enumeration y i y_i yi First of all O ( n ) O(n) O(n) Calculate the following ∏ j ≠ i 1 x i − x j \prod_{j\neq i}\frac{1}{x_i-x_j} ∏j=ixi−xj1, And then because of g ( x ) g(x) g(x) It was not cut off when calculating , So single ( x − x i ) (x-x_i) (x−xi) Divisibility g ( x ) g(x) g(x), direct O ( n ) O(n) O(n) Recursively find ∏ j ≠ i ( x − x j ) \prod_{j\neq i}(x-x_j) ∏j=i(x−xj) that will do ( Pay attention to special judgment x i = 0 x_i=0 xi=0). In this way, the total complexity is reduced to O ( n 2 ) O(n^2) O(n2).
Find the value of a single point
Here, to find the value of a single point means to give k ∉ { x i ∣ 0 ≤ i ≤ n } k\notin \{x_i|0\le i\le n\} k∈/{ xi∣0≤i≤n}, We need to ask for f ( k ) f(k) f(k).
Obviously, we can directly find f ( x ) f(x) f(x) Then bring in the solution , But when our goal is only to find f ( k ) f(k) f(k) when , Doing so is cumbersome and inefficient .
We might as well bring Lagrange interpolation formula directly :
f ( k ) = ∑ i = 0 n y i ∏ j ≠ i k − x j x i − x j f(k)=\sum_{i=0}^ny_i\prod_{j\neq i}\frac{k-x_j}{x_i-x_j} f(k)=i=0∑nyij=i∏xi−xjk−xj Because it is no longer a polynomial , So we can O ( n ) O(n) O(n) Find all in time ∏ j ≠ i ( k − x j ) \prod_{j\neq i}(k-x_j) ∏j=i(k−xj), Then enumerate each time y i y_i yi Just ask ∏ j ≠ i 1 x i − x j \prod_{j\neq i}\frac{1}{x_i-x_j} ∏j=ixi−xj1 了 . Although still O ( n 2 ) O(n^2) O(n2), But it reduces the constant and is simpler .
O(n) Find the value of a single point
Or just ask f ( k ) f(k) f(k).
In most topics applied to pull and insert , this n + 1 n+1 n+1 A point value satisfies subscript continuity , Or equidistant , namely x 1 − x 0 = x 2 − x 1 = . . . = x n − x n − 1 x_1-x_0=x_2-x_1=...=x_n-x_{n-1} x1−x0=x2−x1=...=xn−xn−1.
At this time, we can do some pretreatment ( For example, when the spacing is equal to 1 When , You need to preprocess the inverse of factorial ), Then you can do it once O ( 1 ) O(1) O(1) Find out ∏ j ≠ i 1 x i − x j \prod_{j\neq i}\frac{1}{x_i-x_j} ∏j=ixi−xj1.( Special attention should be paid to symbols )
application
There's a classic question : Calculation ∑ i = 1 n i k \sum_{i=1}^ni^k ∑i=1nik. This problem can obviously be inversed by Stirling O ( k log k ∼ k 2 ) O(k\log k\sim k^2) O(klogk∼k2) solve .
As we all know, this thing is about n n n Of k + 1 k+1 k+1 Sub polynomial , So we can O ( k ) O(k) O(k)( Ignore fast exponents , You can also use a linear sieve ) Before finding out k + 2 k+2 k+2 A point value , Then use the above method O ( k ) O(k) O(k) Pull and insert n n n Answer at , In this way, the total complexity is only O ( k ) O(k) O(k).
More practical scenarios are in some DP In question , For example, you need to ask m m m individual DP Value to transfer , But you find this m m m A function with a point value is a function with a small number of times n n n Sub polynomial , Then you can just ask for the front n + 1 n+1 n+1 individual DP value , The rest can be pulled and inserted .
Generally, it needs inductive proof to see that this is a polynomial , But I will not
边栏推荐
- 中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
- [solved] access denied for user 'root' @ 'localhost' (using password: yes)
- CC2530 common registers for serial communication
- (Supplement) double pointer topic
- Explore Cassandra's decentralized distributed architecture
- Golang anonymous function use
- Thread pool executes scheduled tasks
- function overloading
- Pointcut expression
- 利用MySQL中的乐观锁和悲观锁实现分布式锁
猜你喜欢

于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日

美团一面:为什么线程崩溃崩溃不会导致 JVM 崩溃
![[solved] access denied for user 'root' @ 'localhost' (using password: yes)](/img/71/1ff8ed1d773da99054310f96dca3f8.jpg)
[solved] access denied for user 'root' @ 'localhost' (using password: yes)

Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
![[combinatorics] non descending path problem (number of non descending paths with constraints)](/img/89/bd1a2ddd9632ab5d4b4bee9336be51.jpg)
[combinatorics] non descending path problem (number of non descending paths with constraints)

CC2530 common registers for port initialization

为抵制 7-Zip,列出 “三宗罪” ?网友:“第3个才是重点吧?”

Cocos Creator 2.x 自动打包(构建 + 编译)

Explore Netease's large-scale automated testing solutions see here see here

Deep understanding of grouping sets statements in SQL
随机推荐
PHP converts a one-dimensional array into a two-dimensional array
Simulink oscilloscope data is imported into Matlab and drawn
Explore Netease's large-scale automated testing solutions see here see here
智慧之道(知行合一)
ThreeJS 第二篇:顶点概念、几何体结构
Visual SLAM algorithms: a survey from 2010 to 2016
线程池执行定时任务
What is the material of 13mnnimor? 13mnnimor steel plate for medium and low temperature pressure vessels
网络安全web渗透技术
Pytorch 1.12 was released, officially supporting Apple M1 chip GPU acceleration and repairing many bugs
2022 love analysis · panoramic report of digital manufacturers of state-owned enterprises
There are several APIs of airtest and poco that are easy to use wrong in "super". See if you have encountered them
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
Shentong express expects an annual loss of nearly 1billion
What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR
深入理解 SQL 中的 Grouping Sets 语句
[combinatorics] non descending path problem (number of non descending paths with constraints)
CC2530 common registers
Threejs Part 2: vertex concept, geometry structure
(补)双指针专题