当前位置:网站首页>Uoj 551 [unr 4] campus stroll [good polynomial questions (FOG)]
Uoj 551 [unr 4] campus stroll [good polynomial questions (FOG)]
2022-06-11 07:30:00 【Master. Yi】
Title Description
n n n A little bit m m m Undirected weighted graph with edges , 1 ≤ 1\le 1≤ Border right ≤ V \le V ≤V, Q Q Q Time to ask , from x x x To y y y How many weights sum to w w w The path of , The path can pass through repeated edges and repeated points .
1 ≤ n ≤ 8 , 0 ≤ m ≤ 3 ∗ 1 0 5 , 1 ≤ V ≤ 65000 , 0 ≤ Q ≤ 10000 1\le n\le 8, 0\le m\le 3*10^5,1\le V\le65000,0\le Q\le 10000 1≤n≤8,0≤m≤3∗105,1≤V≤65000,0≤Q≤10000
Topic analysis
violence DP: d p [ i ] [ j ] [ v ] = ∑ k = 1 n d p [ i ] [ k ] [ v ′ ] ∗ n u m [ k ] [ j ] [ v − v ′ ] dp[i][j][v]=\sum\limits_{k=1}^n dp[i][k][v']*num[k][j][v-v'] dp[i][j][v]=k=1∑ndp[i][k][v′]∗num[k][j][v−v′]
It's obviously a convolution .
Can be divided directly NTT, regard as F v = F v ′ ∗ W v − v ′ F_v=F_{v'}*W_{v-v'} Fv=Fv′∗Wv−v′, F F F It's a matrix , such as Code1 , Stuck time limit , Complexity O ( n 3 V log V + n 2 V log 2 V ) O(n^3V\log V+n^2V\log^2V) O(n3VlogV+n2Vlog2V).
You can use some black Technology , Because when divide and conquer, if l ≠ 0 l\neq 0 l=0 be 2 l > r 2l>r 2l>r, therefore F 0 , r − l F_{~0,r-l} F 0,r−l All have been calculated , And then F l , r F_{~l,r} F l,r It's all by F 0 , l − 1 F_{~0,l-1} F 0,l−1 Contributed , So use F l , r ∗ F 0 , r − l F_{l,r}*F_{0,r-l} Fl,r∗F0,r−l As new F l , r F_{l,r} Fl,r, It's not too heavy or too leaky .
So when we divide and conquer l ≠ 0 l\neq 0 l=0 You don't have to continue recursion , It is directly processed at this layer . So the complexity becomes T ( V ) = T ( V 2 ) + n 3 V + n 2 V log V = O ( n 3 V + n 2 V log V ) T(V)=T(\frac V2)+n^3V+n^2V\log V=O(n^3V+n^2V\log V) T(V)=T(2V)+n3V+n2VlogV=O(n3V+n2VlogV)
such as Code2 .You can use some high technology
Make g x , y g_{x,y} gx,y by x → y x\to y x→y Generating function of path weight and number of corresponding schemes , G G G by g g g Corresponding n × n n\times n n×n Matrix , W W W Is the matrix corresponding to the edge weighted polynomial , So there are G = G W + I G=GW+I G=GW+I, therefore G = I I − W G=\frac I{I-W} G=I−WI.
obviously W W W The constant term of each polynomial in the matrix is not 1, therefore I − W I-W I−W Inverse , Find the inverse of a matrix whose element is a polynomial , Use the elementary transformation method similar to Gauss elimination , need n n n The inverse of a polynomial of degree , O ( n 2 ) O(n^2) O(n2) Time DFT, n 3 n^3 n3 Degree point value multiplication and polynomial addition , Complexity O ( n 3 V + n 2 V log V ) O(n^3V+n^2V\log V) O(n3V+n2VlogV), Slightly ( Big ) constant .Or change your mind , Make A ( z ) A(z) A(z) It means that the weight is i i i Matrix generating function of the path of , That is, every coefficient of a polynomial is a matrix , x i x^i xi Indicates that the sum of weights is i i i, The elements in the matrix represent the number of schemes , And order W W W Is the corresponding edge weight matrix polynomial , So there are A = A W + I A=AW+I A=AW+I, therefore A = I I − W A=\frac I{I-W} A=I−WI, But this time W W W It's a polynomial , I I I It is equivalent to the constant term of this polynomial , To find the inverse of a polynomial , Using Newton's iterative method , Yes x 1 = x 0 ( 2 − A x 0 ) x_1=x_0(2-Ax_0) x1=x0(2−Ax0)
There are some things to pay attention to in the implementation , Although the polynomial coefficients are matrices , however DFT Because there are only a few times , So each element of the matrix can be DFT. Then the point value of each position is now a matrix , When doing multiplication, you should pay attention to A x 0 Ax_0 Ax0 The order of cannot be changed , Because the matrix does not satisfy the commutative law . The formula for the initial Newton iteration is A x 0 − I = 0 Ax_0-I=0 Ax0−I=0, Then the square is A x 0 A x 0 − 2 A x 0 + I = 0 Ax_0Ax_0-2Ax_0+I=0 Ax0Ax0−2Ax0+I=0, namely A x 0 ( 2 − A x 0 ) = I Ax_0(2-Ax_0)=I Ax0(2−Ax0)=I. Because left inverse equals right inverse , So the formula can also be written as x 0 A − I = 0 x_0A-I=0 x0A−I=0, Introduction x 1 = ( 2 − x 0 A ) x 0 x_1=(2-x_0A)x_0 x1=(2−x0A)x0, It can be found that the two forms are the same .
The complexity is also O ( n 3 V + n 2 V log V ) O(n^3V+n^2V\log V) O(n3V+n2VlogV)such as Code3 .
边栏推荐
- 群晖DS918创建m.2 固态硬盘SSD读写缓存
- Second remaining learning notes
- Matrix tree theorem
- 黑群晖DSM7.0.1物理机安装教程
- [STL source code analysis] summary notes (1): Opening
- Import on CSDN MD file
- P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
- Sdl-3 YUV playback
- [STL source code analysis] summary notes (5): a good helper for understanding iterators --list
- Directrix of ellipse
猜你喜欢

Decimal to binary

Seata的几种事务模式
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query

Aiop introduction
![Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]](/img/f0/9d4609a53f398636b8062c625f7d3c.jpg)
Uoj 554 [unr 4] challenges Hamilton [find Hamilton path (adjustment method)]

QT 基于QScrollArea的界面嵌套移动

Niuke wrong question 3.1

C language inherits memory management mechanism (unfinished)

Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies

Software testing weekly (issue 75): only when you look down, can you see your true self.
随机推荐
多线程复习总结之解析Volatile关键字
【CF#693 (Div. 3)】B. Fair Division
【POJ3691】DNA repair (AC自动机+DP)
【编译原理】05-语法制导的语义计算——基于翻译模式的语义计算
RTMP protocol
P5431 [template] multiplicative inverse 2
20200803 T3 my friends [divide and conquer NTT optimization recursion]
Summary of classic interview questions
MS office level II wrong question record [8]
Arduino_ STM development record
Building a full-featured NAS server with raspberry pie (05): playing with video and audio & sorting out movies
自动化测试的生命周期是什么?
QT interface nested movement based on qscrollarea
[STL source code analysis] summary notes (5): a good helper for understanding iterators --list
Niuke wrong question 3.1
Use definite integral to calculate triangle area
pmp到底是什么?
[compilation principle] 05- syntax guided semantic computing -- Semantic Computing Based on translation mode
QObject usage skills -- control function class
Analyse du contrat du modèle de taux composé