ZCMU—1894

1894: Power Eggs

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 45   Solved: 18
[ Submit][ Status][ Web Board]

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

【分析】

刘汝佳老师写过经典的鹰蛋dp.....占了做过的优势,所以出的特别快...
首先要注意下边界...不要被数据范围吓到了...只要32步算不出答案,那就是Impossible...
f[i][j]表示剩余i次测试j个鸡蛋能测出来的最大层数
那么对于当前f[i][j]的状态
我们可以考虑,如果从某个位置扔鸡蛋,如果碎了,状态就是f[i-1][j-1]
如果没碎状态就是f[i-1][j],所以 状态转移很明显就是f[i][j]=f[i-1][j-1]+f[i-1][j]
那么考虑一下初始化...
如果只剩一次测试机会,那么f[1][j]就是2,鸡蛋再多也没用。
另外一个情况就是如果这个鸡蛋非常强力...怎么都不碎,那么就是f[i][1],可以达到的位置就是n+1
为什么+1是因为楼层区间是[0,n],总共n+1
【代码】
#include <stdio.h>
long long f[33][33];
int main()
{
    for (int i=1;i<33;i++) f[i][1]=i+1,f[1][i]=2;
    for (int i=2;i<33;i++)
        for (int j=2;j<33;j++)
            f[i][j]=f[i-1][j-1]+f[i-1][j];
    int pp;scanf("%d",&pp);
    while (pp--)
    {
        long long n,m;scanf("%lld%lld",&n,&m);
        for (int i=1;i<33;i++)
            if (f[i][m]-1>=n)
            {
                printf("%d\n",i);
                goto out;
            }
        printf("Impossible\n");
        out:;
    }
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值