UVA - 10934 Dropping water balloons(装满水的气球)(dp)

题意:有k个气球,n层楼,求出至少需要多少次实验能确定气球的硬度。气球不会被实验所“磨损”。

分析:

1、dp[i][j]表示第i个气球,测试j次所能确定的最高楼层。

2、假设第i-1个气球测试j-1次所确定的最高楼层是a,

若第i个气球在测试第一次的时候摔破了,那摔破所在的楼层b<=a+1---------dp[i - 1][j - 1] + 1。

若没摔破,则前i-1个球在此楼层也不会摔破,也就是说当前至少有i个完好的球可以测试以及j-1次机会可以继续测试-------------dp[i][j - 1]。

#pragma comment(linker, "/STACK:102400000, 102400000")
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<iostream>
#include<sstream>
#include<iterator>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<list>
#define Min(a, b) ((a < b) ? a : b)
#define Max(a, b) ((a < b) ? b : a)
const double eps = 1e-8;
inline int dcmp(double a, double b){
    if(fabs(a - b) < eps) return 0;
    return a > b ? 1 : -1;
}
typedef long long LL;
typedef unsigned long long ULL;
const int INT_INF = 0x3f3f3f3f;
const int INT_M_INF = 0x7f7f7f7f;
const LL LL_INF = 0x3f3f3f3f3f3f3f3f;
const LL LL_M_INF = 0x7f7f7f7f7f7f7f7f;
const int dr[] = {0, 0, -1, 1, -1, -1, 1, 1};
const int dc[] = {-1, 1, 0, 0, -1, 1, -1, 1};
const int MOD = 1e9 + 7;
const double pi = acos(-1.0);
const int MAXN = 100 + 10;
const int MAXT = 10000 + 10;
using namespace std;
ULL dp[MAXN][MAXN];
void init(){
    for(int i = 1; i < 64; ++i){
        for(int j = 1; j < 64; ++j){
            dp[i][j] = dp[i][j - 1] + dp[i - 1][j - 1] + 1;
        }
    }
}
int main(){
    int k;
    ULL n;
    init();
    while(scanf("%d%llu", &k, &n) == 2){
        if(!k) return 0;
        k = Min(k, 63);//最多测试63次,所以最多需要63个气球
        bool ok = false;
        for(int i = 0; i <= 63; ++i){
            if(dp[k][i] >= n){
                printf("%d\n", i);
                ok = true;
                break;
            }
        }
        if(!ok) printf("More than 63 trials needed.\n");
    }
    return 0;
}

  

posted @ 2017-02-24 19:23  Somnuspoppy  阅读(370)  评论(0编辑  收藏  举报