Блог пользователя DottedCalculator

Автор DottedCalculator, история, 3 года назад, По-английски

Problem:

Let $$$n$$$ be a positive integer. A Japanese triangle consists of $$$1 + 2 + \dots + n$$$ circles arranged in an equilateral triangular shape such that for each $$$i = 1$$$, $$$2$$$, $$$\dots$$$, $$$n$$$, the $$$i^{th}$$$ row contains exactly $$$i$$$ circles, exactly one of which is coloured red. A ninja path in a Japanese triangle is a sequence of $$$n$$$ circles obtained by starting in the top row, then repeatedly going from a circle to one of the two circles immediately below it and finishing in the bottom row. Here is an example of a Japanese triangle with $$$n = 6$$$, along with a ninja path in that triangle containing two red circles.

Given a Japanese triangle, find the maximum number of red circles in a ninja path.

I found an algorithm using DP that can solve this problem in $$$O(n^2)$$$. Is there a more efficient solution?

  • Проголосовать: нравится
  • +45
  • Проголосовать: не нравится

»
3 года назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In the given example, Is the answer not 4 red circles.

»
3 года назад, скрыть # |
 
Проголосовать: нравится +54 Проголосовать: не нравится
Solution
»
3 года назад, скрыть # |
 
Проголосовать: нравится +34 Проголосовать: не нравится

Using Pólya urn model, one can find a probability distribution with which we have an equal probability of visiting each circle at each layer. We conclude, therefore, that the expected value of red circles is $$$1 + 1/2 + \dots + 1/n = O(\log n)$$$, so there always exists a ninja path with $$$O(\log n)$$$.

Actually, a sharper bound holds, $$$\lfloor \log_2 n \rfloor + 1$$$ (one can prove this via dyadic decomposition or its variations, so maybe there is another $$$O(n\log n)$$$ algorithm but which exploits this decomposition), which is reachable via the example of the following kind

       (R)
      (.)(R)
     (R)(.)(.)
    (.)(.)(.)(R)
   (.)(.)(R)(.)(.)
  (.)(R)(.)(.)(.)(.)
 (R)(.)(.)(.)(.)(.)(.)
(.)(.)(.)(.)(.)(.)(.)(R)
  • »
    »
    3 года назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    Hi,
    as you wrote
    there always exists a ninja path with O(logn)
    How expected number of red balls assures the lenght of ninja path?

    • »
      »
      »
      3 года назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      The expected value generally behaves like the average value. For the last one we have $$$\min A \leq avg A \leq \max A$$$, so if one has the average value $$$x$$$ then there exist both objects that contribute values $$$\geq avg A$$$ and objects that contribute $$$\leq avg A$$$. Of course, this works even if we work via asymptotic expressions rather than via their exact values. To get acquainted with this idea in further depth, I recommend reading about the probabilistic method.

  • »
    »
    3 года назад, скрыть # ^ |
    ← Rev. 3  
    Проголосовать: нравится 0 Проголосовать: не нравится

    Ok now my mind is a bit clearer. I think that if we index positions by both diagonals

        1
       2 1
      3 2 1
     4 3 2 1
    
    and
    
        1
       1 2
      1 2 3
     1 2 3 4
    

    and order things by first diagonal in increasing order, breaking ties by the second diagonal in increasing order, then this problem turns into longest non-decreasing subsequence, since from point (i, j) we can go to (i+1, j) or (i, j+1).

    Hopefully I'm not brainfarting once again. Swistakk is right and I'm dumb. This is the simpler way to think about computing the answer from a configuration of balls though.