Monday, October 8, 2007

Dropping Water Balloons

ACCEPTED again !!! This one was good....
____________________________________________________________________
Question: Dropping Water Balloons
____________________________________________________________________

#include "iostream.h"

long long int floor[64][101];

long long int maxFloors(int t, int k) {
if(floor[t][k] != 0) return floor[t][k];
if(t == 1) floor[t][k] = 1;
else if(k == 1) floor[t][k] = t;
else floor[t][k] = 1 + maxFloors(t - 1, k - 1) + maxFloors(t - 1, k);
return floor[t][k];
}

int main() {
long long int n;
int k, t;
while(true) {
cin >> k;
cin >> n;
if(k == 0) break;
for(t = 1; t <= 63; t++) if(maxFloors(t, k) >= n) break;
if(t > 63) cout << "More than 63 trials needed.\n";
else cout << t << endl;
}
return 0;
}
____________________________________________________________________

No comments:

Contributors