A very detailed explanation: poke here
Example: poj-3783 Balls
Balls
| Time Limit: 1000MS |
|
Memory Limit: 65536K |
| Total Submissions: 1151 |
|
Accepted: 748 |
Description The classic Glass Balls Brain-teaser is often posed as:
"Given-identical glass spheres, you would as-determine the lowest floor in a 100-story building from which they w Ill break when dropped. Assume the spheres is undamaged when dropped below this point. What's the strategy that would minimize the worst-case scenario for number of drops? " Suppose that we had only one ball. We ' d have a to-drop from the 1 to sequence, requiring-drops in the worst case.
Now consider the case where we have both balls. Suppose we drop the first ball from floor N. If It breaks we ' re in the case where we had one ball remaining and we need to drop from floors 1 to n-1 in sequence, Yiel Ding n drops in the worst case (the first ball was dropped once, the second at most n-1 times). However, if it does not break when dropped from floor N, we had reduced the problem to dropping from floors n+1 to 100. In either case we must keep in mind that we ve already used one drop. The minimum number of drops, in the worst case, was the minimum over all n.
You'll write a program to determine the minimum number of drops required, in the worst case, given B balls and an M-stor Y building.Input The first line of input contains a single integer P, (1≤p≤1000), which are the number of data sets that follow. Each data set consists of a containing three (3) decimal integer values:the problem number, followed by a SPAC E, followed by the number of Balls B, (1≤b≤50), followed by a space and the number of floors in the building M, (1≤m ≤1000).Output For each data set, generate one line of output with the following values:the data set number as a decimal integer, a SPAC E, and the minimum number of drops needed for the corresponding values of B and M.Sample Input 4 1 2 10 2 2 100 3 2 300 4 25 900
Sample Output 1 42 143) 244 10
Source Greater New York Regional 2009 |
The AC code is attached:
DP Method One:
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <cstring>5#include <algorithm>6#include <string>7typedefLong Longll;8 using namespacestd;9 Const intMAXN = 1e3 +Ten;Ten Const intINF =0x3f3f3f3f; One intA[MAXN], B[MAXN], C[MAXN]; A intdp[111][MAXN]; - intMain () - { the intN, M; - //scanf ("%d%d", &n, &m); - for(intj =1; J <=1005; ++j) - { +dp[1][J] =J; - } + for(inti =1; I <= -; ++i) A { atdp[i][1] =1; - } - for(inti =2; I <= -; ++i) - { - for(intj =1; J <=1005; ++j) - { inDP[I][J] =inf; - for(intK =1; K <= J; ++k) toDp[i][j] = min (Dp[i][j],max (Dp[i-1][k-1], Dp[i][j-k]) +1); + } - } the //int ans = 111; * intT; $ intCAs;Panax Notoginsengscanf"%d", &t); - while(t--) { thescanf" %d%d%d", &cas, &n, &m); +printf"%d%d\n", CAs, dp[n][m]); A } the + return 0; -}View Code
DP Method II:
Blue Bridge cup-falling cell phone "DP" problem