• URAL1223——DFS—— Chernobyl’ Eagle on a Roof


    Description

    Once upon a time an 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 was walking on the roof. He suddenly said: “Oops! All eggs surely have the same solidity, thus there is such non-negative number E that if one drops an egg from the floor number E, it will not be broken (and so for all the floors below the E-th), but if one drops it from the floor number E+1, the egg will be broken (and the same for every floor higher, than the E-th).” Now Professor Bohr is 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 E may be found by dropping eggs sequentially floor by floor from the lowest one. But there are other strategies to find E for sure with much less amount of experiments. You are to find the least number of eggs droppings, which is sufficient to find number E for sure, even in the worst case. Note that dropped eggs that are not broken can be used again in following experiments.
    The floors are numbered with positive integers starting from 1. If an egg has been broken being dropped from the first floor, you should consider that E is equal to zero. If an egg hasn’t been broken even being dropped from the highest floor, consider that E is also determined and equal to the total number of floors.

    Input

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

    Output

    For each test case output in a separate line the minimal number of experiments, which Niels Bohr will have to make even in the worst case.

    Sample Input

    inputoutput
    1 10
    2 5
    0 0
    
    10
    3
    

    大意:摔蛋,每一个蛋的坚固系数相同,问最少的摔蛋次数,不断二分,直到最后一个不能摔碎,考虑到二分,而且塔的高度不超过1000,所以最多摔碎10个蛋1024就行了

    定义 dp[i][j] 表示用了i个蛋,需要测j楼层的摔蛋次数

    动态转移方程  dp[i][j] = min(dp[i-1][j-1],dp[i][n-j]) 摔碎和没摔碎

    #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 > 10)
                n = 10;
           printf("%d
    ",dfs(n,m));
        }
        return 0;
    }
    

      

  • 相关阅读:
    InterLockedIncrement and InterLockedDecrement函数原理
    矩阵文件书写的简洁代码
    注册自定义URL协议(zhuan)
    求整数的位数
    WinExec unicode 处理
    C++中如何获取对象的名字(变量名,注意不是类名)
    计算所与北大往事回顾
    不尚贤在人事管理中的作用
    寻找适合自己的无资金创业之路
    诺基亚:用薪酬激励员工
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4498318.html
Copyright © 2020-2023  润新知