Page 1 of 1
986 - How Many?
Posted: Thu Nov 16, 2006 8:35 pm
by joy
Posted: Thu Nov 16, 2006 9:50 pm
by ayon
Posted: Tue Nov 28, 2006 11:22 am
by sakhassan
I too really confused about the problem ?? can u pls explain ?
Thanks in advance
Posted: Tue Nov 28, 2006 4:07 pm
by rio
Explain of (3, 1, 2):
There are five kind of mountains for n = 3.
Code: Select all
/\
/\ /\ /\/\ / \
/\/\/\ / \/\ /\/ \ / \ / \
1st mountain has 3 peek of height 1, 0 peek of height 2, 0 peek of height 3.
2nd and 3rd mountain has 1 peek of height 1, 1 peek of height 2, 0 peek of height 3.
4th mountain has 0 peek of height 1, 2 peek of height 2, 0 peek of height 3.
5th mountain has 0 peek of height 1, 0 peek of height 2, 1 peek of height 3.
So the number of mountains that has
exactly r = 1 peek of height k = 2 is 2 (2nd and 3rd).
Other examples of n = 3.
(3, 0, 2) = 2 (1st and 5th)
(3. 0, 1) = 2 (4th and 5th)
(3, 2, 1) = 0 (none)
(3, 1, 3) = 1 (5th)
(3, 0, 4) = 5 (all)
(3, 1, 4) = 0 (none)
I hope this helps.
----
Sory for my poor English.
Posted: Sat Dec 02, 2006 12:17 pm
by sakhassan
Thanks buddy.... Now i can give a try

Posted: Sat Dec 02, 2006 12:52 pm
by joy
Is there any DP solution or anything......
dp
Posted: Sat Dec 02, 2006 1:45 pm
by sohel
Yes, this is a dp problem.
I basically optimized dp[x][y][p][a]..
..ie how many ways I can come to coordinate x,y with p peaks and 'a' indicates last move(down hill or uphill ).
So ultimately the required answer is dp[2*N][0][R][0] // 0 -> downhill
Re: 986 - How Many?
Posted: Thu Jul 02, 2015 1:39 pm
by predicate
some random test cases for debugging:
input :
Code: Select all
3 1 2
10 3 2
10 5 4
20 5 4
20 1 2
20 0 1
output :
Code: Select all
2
2002
69
282172814
1767263190
2892818244