ZSTUOJ 4214: Power Eggs(经典动态规划——鹰蛋问题)

13 篇文章 0 订阅
3 篇文章 0 订阅

4214: Power Eggs

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 125   Solved: 21

Description

Benedict bought K identical power eggs from Dropeggs.com, and now he wants to test them by dropping them from different floors of his building. His building has N floors numbered 1 to NF is an unknown number in the range from 0 to N, inclusive. Each egg will break if dropped from floor F+1 or above, but will not break if dropped from floor F or below. Benedict can drop each egg as many times as he wants from any floor until it breaks. He wants to know the minimum number of egg drops necessary to ensure that he can determine F.

For example, if there are three floors and Benedict has only one egg, then he has to first throw the egg from the first floor, then from the second floor (if the egg survived), and then from the third floor (if the egg survived). Therefore, three drops are required in the worst case

Input

The first line contains one number T (1 ≤ T ≤ 10000) which is the number of test cases, followed by T lines. Each of the next T lines contains two numbers: N, the number of floors (1 ≤ N ≤ 2000000007) and K, the number of eggs (1 ≤ K ≤ 32).

Output

For each of the T lines, print the minimal number of drops required, or if it's greater than 32, print the word Impossible. After that many drops, Benedict gets too tired and cannot continue.

Sample Input

4
10 1
100 2
30 30
2000000000 2

Sample Output

10
14
5
Impossible

鹰蛋问题点击打开链接

经典的鹰蛋问题,首先感谢金巨带我入坑,废掉大量脑细胞之后好不容易看懂点了,

题意:n层楼,k个鸡蛋,求可以测出鸡蛋的最小脆弱度(其实就是鸡蛋最坏条件下可以在哪层楼摔碎)

方法:由于最多可以比较32次,所以只需要开一个dp[32][32]的数组,接着就是恶心的dp思路了。。。。。

设dp[i][j]为i个蛋,j层楼时的鸡蛋的脆弱度

由鹰蛋问题可以知道,dp[1][j] = i, dp[i][1] = 1;


Dp[i][j] = Dp[i][j-1] + Dp[i-1][j-1] + 1;

#include <bits/stdc++.h>
#define LL long long
using namespace std;

LL dp[33][33];//i层楼j个蛋确定的最小次数

void Init()
{
    for(int i=1;i<=32;i++)
        dp[1][i] = i, dp[i][1] = 1;
    for(int i=2;i<=32;i++)
        for(int j=2;j<=32;j++)
            dp[i][j] = dp[i][j-1] + dp[i-1][j-1] + 1;
}
int main()
{
    int T,K;
    LL N;
    Init();
    scanf("%d",&T);
    while(T-- && scanf("%lld %d",&N,&K))
    {
        int pos = -1;
        for(int i=1;i<=32;i++)
        {
            if(dp[K][i] >= N)
            {
                pos = i;
                break;
            }
        }
        if(pos!=-1) printf("%d\n",pos);
        else printf("Impossible\n");
    }
    return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值