题意:一个懒惰的人,想要通过水球从高楼抛下,算出高楼的高度,水球只要不摔坏,就可以继续使用。每个球的使用次数不得超过63。给你球的个数K,和楼高n
问:你能否在每个球次数不超过63情况下测出楼高。
分析:动态规划,递推思想
num[i][j]表示第i球第j次可测量的楼高
num[i][j] = num[i-1][j-1] + 1 +num[i][j-1]
样例:
Sample Input
2 100
10 786599
4 786599
60 1844674407370955161
63 9223372036854775807
0 0
Sample Output
14
21
More than 63 trials needed.
61
63
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
long long num[101][64];
memset(num,0,sizeof(num));
for(int i=1; i<101; i++)
{
for(int j=1; j<64; j++)
{
num[i][j] = num[i-1][j-1]+1+num[i][j-1];
}
}
int k;
long long n;
while(cin >> k >> n)
{
int flag = 0;
if(k==0)
break;
for(int i=0;i<64;i++)
{
if(num[k][i]>=n)
{
flag = 1;
cout << i << endl;
break;
}
}
if(!flag) cout << "More than 63 trials needed." << endl;
}
return 0;
}