5 × 5 5 \times 5 UR grid

The prince want to meet the princess , but "Not everything is easy" .

The prince must go throught 5 × 5 5\times 5 grid , the prince is at the point ( 0 , 0 ) (0,0) , the princess is at the point ( 5 , 5 ) (5,5)

The prince can go only u p up and r i g h t right

where there are 3 3 dangerous points ,

At ( 2 , 2 ) (2,2) there is a mud pool , at ( 3 , 3 ) (3,3) there is a snake , at ( 4 , 4 ) (4,4) there is a mine .

Safe path is a way that the prince can go in , without passing throught any dangerous point.

What is the number of SAFE PATHS (going only u p up and r i g h t right )


The answer is 48.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Jordan Cahn
Dec 26, 2018

The number of paths from ( 0 , 0 ) (0,0) to ( m , n ) (m,n) moving only up or right is ( m + n m ) {m+n \choose m} (you have to move a total of m + n m+n times, you pick m m times to move right). Furthermore, the number of paths that go through a specific point ( a , b ) (a,b) on the way to ( m , n ) (m,n) is simply [ paths from ( 0 , 0 ) to ( a , b ) ] [ paths from ( a , b ) to ( m , n ) ] [\text{paths from }(0,0)\text{ to } (a,b)]\cdot[\text{paths from }(a,b)\text{ to } (m,n)] .

We now use the principle of inclusion-exclusion Safe paths = Total paths Paths through one trap + Paths through two traps Paths through three traps \text{Safe paths} = \text{Total paths} - \text{Paths through one trap} + \text{Paths through two traps} - \text{Paths through three traps} Let T 1 T_1 , T 2 T_2 and T 3 T_3 denote the three traps. Safe paths = ( 10 5 ) = 252 Paths through one trap = Paths through T 1 + Paths through T 2 + Paths through T 3 = ( 4 2 ) ( 6 3 ) + ( 6 3 ) ( 4 2 ) + ( 8 4 ) ( 2 1 ) = 6 20 + 20 6 + 70 2 = 380 Paths through two traps = Paths through T 1 and T 2 + Paths through T 1 and T 3 + Paths through T 2 and T 3 = ( 4 2 ) ( 2 1 ) ( 4 2 ) + ( 4 2 ) ( 4 2 ) ( 2 1 ) + ( 6 3 ) ( 2 1 ) ( 2 1 ) = 6 2 6 + 6 6 2 + 20 2 2 = 224 Paths through three traps = Paths through T 1 and T 2 and T 3 = ( 4 2 ) ( 2 1 ) ( 2 1 ) ( 2 1 ) = 6 2 2 2 = 48 \begin{aligned} \text{Safe paths} &= {10\choose 5} = 252 \\ \text{Paths through one trap} &= \text{Paths through }T_1 + \text{Paths through }T_2 + \text{Paths through }T_3\\ &= {4 \choose 2}{6 \choose 3} + {6 \choose 3}{4 \choose 2} + {8 \choose 4}{2 \choose 1} \\ &= 6\cdot 20 + 20\cdot 6 + 70\cdot 2 = 380 \\ \text{Paths through two traps} &= \text{Paths through }T_1 \text{ and } T_2 + \text{Paths through }T_1 \text{ and } T_3 + \text{Paths through }T_2 \text{ and } T_3 \\ &= {4 \choose 2}{2 \choose 1}{4 \choose 2} + {4 \choose 2}{4 \choose 2}{2 \choose 1} + {6 \choose 3}{2 \choose 1}{2 \choose 1} \\ &= 6\cdot 2\cdot 6 + 6\cdot 6\cdot 2 + 20\cdot 2\cdot 2 = 224 \\ \text{Paths through three traps} &= \text{Paths through }T_1 \text{ and } T_2 \text{ and } T_3 \\ &= {4 \choose 2}{2 \choose 1}{2 \choose 1}{2 \choose 1} \\ &= 6\cdot 2\cdot 2 \cdot 2 = 48 \end{aligned}

Thus, we have Safe paths = 252 380 + 224 48 = 48 \text{Safe paths} = 252 - 380 + 224 - 48 = \boxed{48}

Hosam Hajjir
Dec 25, 2018

I implemented the following algorithm using Microsoft Excel Visual Basic for Applictations (VBA).

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
Public Sub ibrahim()

n = routes(0, 0)

MsgBox (n)

End Sub

Public Function routes(ByVal i As Integer, ByVal j As Integer) As Integer

If i = 5 And j = 5 Then

   routes = 1

   Exit Function

End If

If (i > 5) Or (j > 5) Or (i = 2 And j = 2) Or (i = 3 And j = 3) Or (i = 4 And j = 4) Then

   routes = 0

   Exit Function

End If

k = routes(i + 1, j) + routes(i, j + 1)

routes = k

End Function

The output of the program is 48 48 .

You can solve with "Principle of inclusion and exclusion"

The answer will be 252 380 + 224 48 = 48 252-380+224-48=48

ابراهيم فقرا - 2 years, 5 months ago

Log in to reply

Where do these numbers come from? I only see ( 10 5 ) = 252 \binom {10}{5} = 252 and 224 must come from 32 7 32 \cdot 7 , right?

Henry U - 2 years, 5 months ago

Log in to reply

Hey dear ! At fact i'm not good in english , so i didn't share my solution because i need to use it . The total paths are ( 1 0 ) 5 = 252 \binom 10 5 =252 There are 6 ( 3 ) 4 ( 2 = ) 120 6 \binom 3 * 4\binom 2 =120 paths that will pass through the first dangerous point . The same calculation the the second dangerous point . 120 120 There are 8 ( 4 ) 2 ( 1 = ) 140 8 \binom 4 * 2\binom 1=140 paths that will pass through the third point . The sum is 120 + 120 + 140 = 380 120+120+140=380 These 380 are dangerous so we subtract them , but watch out , we calculated some paths more than one time . So we have subtracted them more than one time . So we add the paths which will pass through 2 points at least , the sum will be 6 2 6+20 2 2+6 6 2=224 . But again we added some paths more than one time , which they path through the 3 points . The number of these paths is 6 2 2*2=48 so we have to subtract 48 , We get 252-380+224-48 . If you understand inclusion and exclusion this will help you a lot . :)

ابراهيم فقرا - 2 years, 5 months ago

Log in to reply

@ابراهيم فقرا Now I understand. Thank you very much, and your English isn't bad!

Henry U - 2 years, 5 months ago

@ابراهيم فقرا Sorry couldn't edit my comment Hey dear ! At fact i'm not good in english , so i didn't share my solution because i need to use it . The total paths are ( 10 5 ) = 252 \binom {10} 5 =252 There are ( 6 3 ) ( 4 2 ) = 120 \binom 6 3 * \binom 4 2 =120 paths that will pass through the first dangerous point . The same calculation the the second dangerous point . 120 120 There are ( 8 4 ) ( 2 1 ) = 140 \binom 8 4 * \binom 2 1=140 paths that will pass through the third point . The sum is 120 + 120 + 140 = 380 120+120+140=380 These 380 are dangerous so we subtract them , but watch out , we calculated some paths more than one time . So we have subtracted them more than one time . So we add the paths which will pass through 2 points at least , the sum will be 6 × 2 × 6 + 20 × 2 × 2 + 6 × 6 × 2 = 224 6\times 2\times 6+20\times 2\times 2+6\times 6\times 2=224 . But again we added some paths more than one time , which they path through the 3 points . The number of these paths is 6 2 2 2 = 48 6*2*2*2=48 so we have to subtract 48 , We get 252-380+224-48 . If you understand inclusion and exclusion this will help you a lot . :)

ابراهيم فقرا - 2 years, 5 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...