Lin1991122's blog

By Lin1991122, history, 3 hours ago, In English

Ignoring TLE,let's calculate $$$f(s)$$$ at first.I'd like to transform the problem into this:divide the sequence into some segments whose length is more than 2,each segment's cost is the first number times the length -1.For example,2 2 2,it's cost is 4.Set $$$f_{i,j}$$$ means,explore first i elements,the first number of the last segment is j.It's easy to calculate now.

$$$\begin{cases} & f_{i,j}=f_{i-1,j}+j \\ & f_{i,a_{i-1}}=\min(f_{i,a_{i-1}},\min_1^9f_{i-2,j}+a_{i-1}),i\geq4 \end{cases}$$$

Means that,I can append $$$i_{th}$$$ number just in the back of the last segment,or make a new segment with $$$a_{i-1}$$$.

It costs $$$O(n)$$$ for each query,and got TLE.We can use ddp.Use matrix to draw the dp.Especially,the $$$\times$$$ means add.the $$$+$$$ means $$$\min$$$.Let $$$\min_i=\min_1^9 f_{i,j}$$$,we can design the vector as follows:

$$$\begin{bmatrix} f_{i-1,1}\\ f_{i-1,2}\\ f_{i-1,3}\\ f_{i-1,4}\\ f_{i-1,5}\\ f_{i-1,6}\\ f_{i-1,7}\\ f_{i-1,8}\\ f_{i-1,9}\\ \min_{i-1}\\ \min_{i-2} \end{bmatrix}$$$

I'd like to show you $$$i_{th}$$$ matrix with $$$a_{i-1}=2$$$("i" means inf):

$$$\begin{bmatrix} 1& i& i& i &i& i& i& i& i &i &i \\ i& 2& i& i &i& i& i& i& i &i &2 \\ i& i& 3& i &i& i& i& i& i &i &i \\ i& i& i& 4 &i& i& i& i& i &i &i \\ i& i& i& i &5& i& i& i& i &i &i \\ i& i& i& i &i& 6& i& i& i &i &i \\ i& i& i& i &i& i& 7& i& i &i &i \\ i& i& i& i &i& i& i& 8& i &i &i \\ i& i& i& i &i& i& i& i& 9 &i &i \\ 1& 2& 3& 4 &5& 6& 7& 8& 9 &i &2 \\ i& i& i& i &i& i& i& i& i &0 &i \end{bmatrix}$$$

It's easy to use segment tree to solve this,but might TLE.Just use blocks,since the len of each query is const.

Also,I'm working on how to get the inverse of the matrix.Guass might work.

code

  • Vote: I like it
  • +3
  • Vote: I do not like it

»
3 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

2004G - Substring Compression add this to your blog

  • »
    »
    3 hours ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    where?plz.