题意是由气球个数加楼层确定最少的实验次数
可转化为 气球加实验次数 所能确定的最高楼层(这样楼层确定时 实验次数必定是最少的)
注意数组d与n都为ull
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
using namespace std;
const int maxk=100;
const int maxa=63;
unsigned long long d[maxk+1][maxa+1];
int main(){
memset(d,0,sizeof(d));
for(int i=1;i<=maxk;i++)
for(int j=1;j<=maxa;j++){
d[i][j]=d[i-1][j-1]+1+d[i][j-1];
}
int k;
unsigned long long n;
while(cin>>k>>n&&k){
int flag=-1;
for(int i=1;i<=maxa;i++){
if(d[k][i]>=n)
{
flag=i;
break;
}
}
if(flag>=0) cout<<flag<<endl;
else cout << "More than " << maxa << " trials needed.\n";
}
return 0;
}