Hi! I found a type of problems I couldn't solve, but I read that we can solve them using FFT or generating functions. I don't know how to use these approaches here, can someone help me please? (I didn't found a tutorial, just discussions) The problems are: - Square Grid - The last problem in this note of Petr's blog - Kalel, The Jumping Frog Would be nice for me a more detailed explanation or a resource to check
Problems are nice. +1 on that.
I tried to solve the first problem using ChatGPT, but it's struck on solving the easier version only.
Gave a DP solution.
Long reply, but it ends with
It ends with,
It ends with,
At this point, I gave up.
I tried to calculate $$$\text{lcm}(1, 2, \dots, 16)$$$ using ChatGPT, but it's not as easy as it seems. Apparently ChatGPT is not so good at manipulating formulas and doing calculations.
For the last problem: you can simply treat the problem as usual matrix exponentiation problem but using a polynomial in every entry of the matrix to represent the energy spent, naive multiplication is enough for AC in something like O(D^3 K^2 logN). You can further optimize it using some polynomial operations down to O(KD logKD logN).
As for the others, I have no idea.
Ohh interesting approach, it's a really cool solution. Thx!
Firstly, try to solve a problem only on x-axis.
This means try to implement a function F(x1, x2) that returns Poly, whose k'th coefficient is number of ways to go from x1 to x2 without visiting 0. Here, it would be convenient to assume that we can visit x2 more than one time.
Secondly, let $$$X = F(x_1, x_2)$$$, $$$X' = F(x_2, x_2)$$$, same for $$$Y$$$ and $$$Y'$$$.
Then, divide k'th coefficient of every Poly by $$$k!$$$.
Let $$$A = X \times Y$$$, $$$A' = X' \times Y'$$$
Multiply k'th coefficients of $$$A$$$ and $$$A'$$$ by $$$k!$$$. Now, one can see that $$$A_k = \sum_{i=0}^{k} X_i \times Y_{k-i} \times \binom{k}{i}$$$ =
"from $$$x_1$$$ to $$$x_2$$$ in $$$i$$$ moves" $$$\times$$$ "from $$$y_1$$$ to $$$y_2$$$ in $$$k-i$$$ moves" $$$\times$$$ "choose $$$i$$$ moves from $$$(k-i)+i$$$". Same for $$$A'$$$.
Now, the answer is just $$$A \div A'$$$, because $$$A_k$$$ is the number of ways to go from (x1, y1) to (x2, y2) in k moves, but we can visit (x2, y2) more that once, and $$$A'_k$$$ is the number of ways to go from (x2, y2) to (x2, y2) in k moves.