MBEEWALK - Bee Walk
A bee larva living in a hexagonal cell of a large honey comb decides to creep for a walk. In each “step” the larva may move into any of the six adjacent cells and after n steps, it is to end up in its original cell. Your program has to compute, for a given n, the number of different such larva walks.
The ﬁrst line contains an integer giving the number of test cases to follow. Each case consists of one line containing an integer n, where 1 ≤ n ≤ 14. SAMPLE INPUT 2 2 4
For each test case, output one line containing the number of walks. Under the assumption 1 ≤ n ≤ 14, the answer will be less than 2^31. SAMPLE OUTPUT 6 90
Instead of using maps for negative coordinates, it is better to offset the origin by some amount. Then an array can be used.
Understand hexagonal coordinate system, game is over
simple dp :D
Last edit: 2017-05-25 08:31:37
I hard coded the value but I cannot understand how to memoize it ! When using Maps , the container is always empty initially ! Which is one of the values which leads to TLE as it was taking 2 seconds for n=14 !
Deepak Singh Tomar:
for those who are stuck at how to store intermediate results for -ve coordinates... use map... :)
Awesome !! :D
problem is not displaying.
|Cluster:||Cube (Intel G860)|
|Languages:||ADA95 ASM32 BASH BF C CSHARP CPP C99 CLPS LISP clisp LISP sbcl D FORTRAN HASK ICON ICK JAVA LUA NEM NICE OCAML PAS-GPC PAS-FPC PERL PHP PIKE PRLG-swi PYTHON RUBY SCM guile SCM qobi ST WHITESPACE|