The prince want to meet the princess , but "Not everything is easy" .
The prince must go throught 5 × 5 grid , the prince is at the point ( 0 , 0 ) , the princess is at the point ( 5 , 5 )
The prince can go only u p and r i g h t
where there are 3 dangerous points ,
At ( 2 , 2 ) there is a mud pool , at ( 3 , 3 ) there is a snake , at ( 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 and r i g h t )
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.
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 |
|
The output of the program is 4 8 .
You can solve with "Principle of inclusion and exclusion"
The answer will be 2 5 2 − 3 8 0 + 2 2 4 − 4 8 = 4 8
Log in to reply
Where do these numbers come from? I only see ( 5 1 0 ) = 2 5 2 and 224 must come from 3 2 ⋅ 7 , right?
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 ( 0 1 ) 5 = 2 5 2 There are 6 ( ∗ 3 ) 4 ( = 2 ) 1 2 0 paths that will pass through the first dangerous point . The same calculation the the second dangerous point . 1 2 0 There are 8 ( ∗ 4 ) 2 ( = 1 ) 1 4 0 paths that will pass through the third point . The sum is 1 2 0 + 1 2 0 + 1 4 0 = 3 8 0 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 . :)
Log in to reply
@ابراهيم فقرا – Now I understand. Thank you very much, and your English isn't bad!
@ابراهيم فقرا – 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 ( 5 1 0 ) = 2 5 2 There are ( 3 6 ) ∗ ( 2 4 ) = 1 2 0 paths that will pass through the first dangerous point . The same calculation the the second dangerous point . 1 2 0 There are ( 4 8 ) ∗ ( 1 2 ) = 1 4 0 paths that will pass through the third point . The sum is 1 2 0 + 1 2 0 + 1 4 0 = 3 8 0 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 + 2 0 × 2 × 2 + 6 × 6 × 2 = 2 2 4 . 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 = 4 8 so we have to subtract 48 , We get 252-380+224-48 . If you understand inclusion and exclusion this will help you a lot . :)
Problem Loading...
Note Loading...
Set Loading...
The number of paths from ( 0 , 0 ) to ( m , n ) moving only up or right is ( m m + n ) (you have to move a total of m + n times, you pick m times to move right). Furthermore, the number of paths that go through a specific point ( a , b ) on the way to ( m , n ) is simply [ paths from ( 0 , 0 ) to ( a , b ) ] ⋅ [ paths from ( a , b ) 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 Let T 1 , T 2 and T 3 denote the three traps. Safe paths Paths through one trap Paths through two traps Paths through three traps = ( 5 1 0 ) = 2 5 2 = Paths through T 1 + Paths through T 2 + Paths through T 3 = ( 2 4 ) ( 3 6 ) + ( 3 6 ) ( 2 4 ) + ( 4 8 ) ( 1 2 ) = 6 ⋅ 2 0 + 2 0 ⋅ 6 + 7 0 ⋅ 2 = 3 8 0 = Paths through T 1 and T 2 + Paths through T 1 and T 3 + Paths through T 2 and T 3 = ( 2 4 ) ( 1 2 ) ( 2 4 ) + ( 2 4 ) ( 2 4 ) ( 1 2 ) + ( 3 6 ) ( 1 2 ) ( 1 2 ) = 6 ⋅ 2 ⋅ 6 + 6 ⋅ 6 ⋅ 2 + 2 0 ⋅ 2 ⋅ 2 = 2 2 4 = Paths through T 1 and T 2 and T 3 = ( 2 4 ) ( 1 2 ) ( 1 2 ) ( 1 2 ) = 6 ⋅ 2 ⋅ 2 ⋅ 2 = 4 8
Thus, we have Safe paths = 2 5 2 − 3 8 0 + 2 2 4 − 4 8 = 4 8