当前位置:网站首页>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 .
边栏推荐
- big. Js-- use / instance
- MS office level II wrong question record [7]
- 【AtCoder1980】Mysterious Light(数学模拟)
- Wc2020 guessing game
- Rabin-Miller素数测试
- Summary of classic interview questions
- [analysis of STL source code] summary notes (3): vector introduction
- MFC custom string linked list
- [STL source code analysis] summary notes (10): hashtable exploration
- 测试4年裸辞失业,面试15k的测试岗被按在地上摩擦,结局让我崩溃大哭...
猜你喜欢

Miscellany C language
![P5431 [template] multiplicative inverse 2](/img/63/1cb95a55c9ce9b92d6d55381d0215b.jpg)
P5431 [template] multiplicative inverse 2

Directrix of ellipse

黑群晖DSM7.0.1物理机安装教程

【Oracle 数据库】奶妈式教程day03 排序查询

Qstring to hexadecimal qstring

2022 melting welding and thermal cutting exam exercises and answers

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

Summary of classic interview questions
![[Oracle database] mammy tutorial day03 Sorting Query](/img/ea/24c9495a2ef4f1786f7b7852bde321.png)
[Oracle database] mammy tutorial day03 Sorting Query
随机推荐
MySQL设置管理员密码无法生效的案例一则
SQLZOO刷题记录-3
Seata的几种事务模式
2022低压电工考题及在线模拟考试
gaussDB for redis和 redis的区别?
CRMEB/V4.4标准版打通版商城源码小程序公众号H5+App商城源码
2022 low voltage electrician test questions and online simulation test
RTMP protocol
P3327 [sdoi2015] approximate sum (Mobius inversion + formula)
Classification of MNIST datasets with keras
[analysis of STL source code] summary note (4): behind the scenes hero allocator
[analysis of STL source code] summary notes (3): vector introduction
Use definite integral to calculate triangle area
MFC auxiliary CString string splicing
Simple configuration of vscade
欧拉定理及扩展(附证明)
Software testing weekly (issue 75): only when you look down, can you see your true self.
[analysis of STL source code] summary notes (6): Design of iterator and magical traits
2022.5.30-6.5 AI行业周刊(第100期):三年时光
pmp到底是什么?