Ural1223--dfs--chernobyl ' Eagle on a Roof

Source: Internet
Author: User

Description

Once upon a time a Eagle made a nest on the roof of a very large building. Time went by and some eggs appeared in the nest. There was a sunny day, and Niels Bohr were walking on the roof. He suddenly said: "Oops! All eggs surely has the same solidity, thus there is such non-negative number EThat if one drops a egg from the floor number E, it is not being broken (and so for all the floors below the E-th), but if one drops it from the floor number E+1, the egg would be broken (and the same for every floor higher, than the E-th). " Now Professor Bohr are going to organize a series of experiments (i.e. drops). The goal of the experiments is to determine the constant E. It is evident that number EMay is found by dropping eggs sequentially floor by floor from the lowest one. But there is other strategies to find EFor sure with much less amount of experiments. You were to find the least number of eggs droppings, which was sufficient to find number EFor sure, even in the worst case. Note that dropped eggs that is not broken can is used again in following experiments. The floors is numbered with positive integers starting from 1. If an egg have been broken being dropped from the first floor and you should consider that Eis equal to zero. If an egg hasn ' t been broken even being dropped from the highest floor, consider that Eis also determined and equal to the total number of floors.

Input

Input contains multiple (up to) test cases. Each line was a test case. Each test case consists of numbers separated with a space:the number of eggs, and the number of floors. Both numbers is positive and does not exceed 1000. Tests'll end with the line containing and the zeroes.

Output

For all test case output in a separate line the minimal number of experiments, which Niels Bohr'll has to make even in The worst case.

Sample Input

input Output
1 102 50 0
103

The main idea: wrestling eggs, each egg of the same solid coefficient, ask the fewest number of broken eggs, constantly two points, until the last one can not be broken, considering the two points, and the height of the tower not more than 1000, so the most broken 10 eggs 1024 on the line

Definition dp[i][j] means I have an egg, I need to measure the number of balls on J floor.

Dynamic transfer equation Dp[i][j] = min (dp[i-1][j-1],dp[i][n-j]) broken and not broken

#include <cstdio> #include <cstring> #include <algorithm>using namespace Std;int dp[15][1110];const int inf = 0x3f3f3f3f;int dfs (int x,int y) {    if (Dp[x][y])        return dp[x][y];    if (x = = 1) {        dp[x][y] = y;        return y;    }    if (y <= 2) {        dp[x][y] = y;        return y;    }    int min1 = INF;    for (int i = 2; i < Y; i++) {        int max1 = max (Dfs (x,y-i) +1,dfs (x-1,i-1) +1);        min1 = min (min1,max1);    }        Dp[x][y] = min1;        return min1;} int main () {    int n,m;    while (~SCANF ("%d%d", &n,&m) && (n&&m)) {        if (n > Ten)            n = ten;       printf ("%d\n", DFS (N,m));    }    return 0;}

  

Ural1223--dfs--chernobyl ' Eagle on a Roof

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.