Find the time it takes for fluid to reach the nth cup

This is an additional task that I received from my teacher.

The cups are arranged in a tree structure, something like this:

  1
 2 3
4 5 6

It takes 10 seconds to fill cup 1, then it overflows into cups 2 and 3. (Assume there is no spill). Cups 2 and 3 then take 20 seconds to fill due to separation of the water flow. In total, it takes 30 seconds to fill cup 3 by pouring water into cup 1. For cup 5, it takes 50 seconds, etc.

Below is a table with the correct values ​​for the row and seconds it takes to reach the next cup.

    1(10)
 2(30) 3(30)
4(70) 5(50) 6(70)

The proposed problem is to solve this for an arbitrary number of rows with a boundary r <= 50: Given row r and cup c, how long does it take to fill this cup?

I roll my head over this for about 24 hours, and I'm no closer to solving it. I know this has something to do with Pascal's triangle and recursion. I would also like to note that this is not a gradient task, but simply an unclassified interesting problem proposed by the teacher.

EDIT: Added a more understandable data structure along with my notes.

1:   1
2:  1 2
3: 1 2 3

Given this structure, I found that the proportions of the distribution of the water flow to the cups below it are related to the Pascal triangle in accordance with the following formula

h(r,c)=P(n,c)/2^(n-1)
where P(n,c) returns the number contained in the according row in Pascal triangle

Then I used this to calculate the seconds with the following formula:

t(r,c)=(2^(n-1)/P(n,c))*10

, - , 2 .

, , (r-1, c) (r-1, c-1) , - .

+4
2

, : -

if(T(r-1,c-1)<T(r,c)) {

  T(r,c) = T(r-1,c) + (1-F(r-1,c)*(T(r-1,c)-T(r-1,c-1)))/(F(r-1,c-1)+F(r-1,c));
  F(r,c) = F(r-1,c) + F(r-1,c-1);
}

else if(T(r-1,c)<T(r-1,c-1)) {

   T(r,c) = T(r-1,c-1) + (1-F(r-1,c-1)*(T(r-1,c-1)-T(r-1,c)))/(F(r-1,c-1)+F(r-1,c));
   F(r,c) = F(r-1,c) + F(r-1,c-1);
}

else {

   T(r,c) = T(r-1,c-1) + 1/F(r-1,c-1);
   F(r,c) = F(r-1,c-1);
}

for corner cases like  
T(r,1) = T(r-1,1) + 2/F(r-1,1) and T(r,r) = T(r-1,r-1) + 2/F(r-1,r-1) and T(1,1) = 10

F(1,1) = 1/10  

: , ,

0

Source: https://habr.com/ru/post/1525651/


All Articles