zoukankan      html  css  js  c++  java
  • 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;
    }
    

      

  • 相关阅读:
    【转】DOS命令大全(远程命令)
    system CPU占用率过高与91助手的关系
    要像管理咨询一样去做软件需求调研
    近两个月工作日志
    ECSHOP:首页实现显示子分类商品,并实现点击Tab页切换分类商品
    奋战5个小时解决诡异的PHP“图像XX因其本身有错无法显示”的问题
    SVN强制添加日志出现E205000错误解决方法
    pdf文件之itextpdf操作实例
    验证码实例
    Struts2拦截器记录系统操作日志
  • 原文地址:https://www.cnblogs.com/zero-begin/p/4498318.html
Copyright © 2011-2022 走看看