"The Duck and the golden egg" The duck has hidden its golden egg somewhere in the Mx Ngrid, to seize the golden egg we need to
traverse the board spirally starting with the index 0,0. The last index position in the spiral ppath is where the golden egg is hidden. Find
the spiral path to reach the golden egg.
Input: 341234670911216 Output: 12349612 116 70 Explanation: The first line of input will be the row size (M), column
size(N) of an array and followed by the MxNarray elements. The
output is to print the Mx Narray spirally starting with the index 0,0.
Answers
Answered by
0
Answer:
itsitst8ydts857a7d0y9746
Answered by
0
Answer:
INT_MAX = 32767
def eggDrop(n, k):
eggFloor = [[0 for x in range(k + 1)] for x in range(n + 1)]
for i in range(1, n + 1):
eggFloor[i][1] = 1
eggFloor[i][0] = 0
for j in range(1, k + 1):
eggFloor[1][j] = j
for i in range(2, n + 1):
for j in range(2, k + 1):
eggFloor[i][j] = INT_MAX
for x in range(1, j + 1):
res = 1 + max(eggFloor[i-1][x-1], eggFloor[i][j-x])
if res < eggFloor[i][j]:
eggFloor[i][j] = res
return eggFloor[n][k]
n = 2
k = 36
print(str(n) + "eggs and "+ str(k) + " floors is " + str(eggDrop(n, k)))
Explanation:
We assume the following:
- An egg that makes it through a fall can be utilised once again.
- A cracked egg needs to be thrown away.
- All eggs are affected in the same way by a fall.
- An egg would shatter if it were dropped from a higher floor since eggs break when they are dropped.
- An egg would survive a shorter fall if it can survive a fall.
- It is not excluded that windows on the first floor break eggs, just as it is not excluded that windows on the 36th story do not cause an egg to crack.
#SPJ2
Similar questions