- Related Questions & Answers
- C Program for Tower of Hanoi
- C++ Program for Dijkstra’s shortest path algorithm?
- C/C++ Program for nth Catalan Number?
- C Program to Multiply two Floating Point Numbers?
- C program to find the length of a string?
- C Program to Check if all digits of a number divide it
- C Program to Check if a Given String is a Palindrome?
- Write a program to Delete a Tree in C programming
- Write a C program to print “ Tutorials Point ” without using a semicolon
- Sum of the nodes of a Singly Linked List in C Program
- Sum of first n natural numbers in C Program
- C Program for simple interest?
- Area of a n-sided regular polygon with given Radius in C Program?
- Area of a leaf inside a square in C Program?
- C Program for Area of a square inscribed in a circle which is inscribed in a hexagon?

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this article, we will learn about the solution to the problem statement given below.

**Problem statement **− Suppose that we want to know which stories in a 40-story building are safe to drop the eggs from, and which of those will cause the eggs to get damaged on
landing with the help of eggs. We need to display a minimum number of trails to check the stories.

Now let’s observe the solution in the implementation below −

# dynamic programming INT_MAX = 32767 # to get minimum trials def eggDrop(n, k): # intialization eggFloor = [[0 for x in range(k + 1)] for x in range(n + 1)] # base case for i in range(1, n + 1): eggFloor[i][1] = 1 eggFloor[i][0] = 0 # We always need j trials for j in range(1, k + 1): eggFloor[1][j] = j # Fill rest of the entries 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] # main n = 4 k = 40 print("Minimum number of trials in worst case scenario with " + str(n) + " eggs and "+ str(k) + " floors is " + str(eggDrop(n, k)))

Minimum number of trials in worst case scenario with 4 eggs and 40 floors is 6

All the variables are declared in the local scope and their references are seen in the figure above.

In this article, we have learned about how we can make a Python Program for Egg Dropping Puzzle.

Advertisements