示例#1
0
int main()
{
    int n = 2, k = 100;
    printf ("\nMinimum number of trials in worst case with %d eggs and "
             "%d floors is %d \n", n, k, eggDrop(n, k));
    return 0;
}
示例#2
0
int Discrete::eggDrop(int negg, int nfloor)
{
    if (nfloor==1 || nfloor==0)
        return nfloor;
    else if (negg==1)
        return nfloor;
    else
    {
        int res=INT_MAX;
        for (int i=1; i<=nfloor; i++)
        {
            res = min(res, max(eggDrop(negg-1, i-1), eggDrop(negg, nfloor-i)));
        }
        return res+1;
    }

}
示例#3
0
	/* Function to get minimum number of trials needed in worst
	  case with n eggs and k floors */
	int eggDrop(int n, int k)
	{
		// If there are no floors, then no trials needed. OR if there is
		// one floor, one trial needed.
		if (k == 1 || k == 0)
			return k;

		// We need k trials for one egg and k floors
		if (n == 1)
			return k;

		int min = INT_MAX, x, res;

		// Consider all droppings from 1st floor to kth floor and
		// return the minimum of these values plus 1.
		for (x = 1; x <= k; x++)
		{
			res = max(eggDrop(n-1, x-1), eggDrop(n, k-x));
			if (res < min)
				min = res;
		}

		return min + 1;
	}