UVA - 10934 Dropping water balloons(装满水的气球)(dp)
生活随笔
收集整理的這篇文章主要介紹了
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; }
轉載于:https://www.cnblogs.com/tyty-Somnuspoppy/p/6439957.html
總結
以上是生活随笔為你收集整理的UVA - 10934 Dropping water balloons(装满水的气球)(dp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 平安银行消费专用备用金怎么申请?申请条件
- 下一篇: js正则学习分享