| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 664 | Accepted: 463 |
Description
"Given two identical glass spheres, you would like to determine the lowest floor in a 100-story building from which they will break when dropped. Assume the spheres are undamaged when dropped below this point. What is the strategy that will minimize the worst-case scenario for number of drops?"
Input
Output
Sample Input
4
1 2 10
2 2 100
3 2 300
4 25 900
Sample Output
1 4
2 14
3 24
4 10
Source
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const INF = 0xffffff;
int dp[1005][55];
void cal()
{
for(int i = 0; i <= 1001; i++)
for(int j = 0; j <= 51; j++)
dp[i][j] = INF;
for(int i = 0; i <= 51; i++)
dp[0][i] = 0;
for(int i = 1; i <= 1001; i++)
for(int j = 1; j <= 51; j++)
for(int k = 1; k <= i; k++)
dp[i][j] = min(dp[i][j], max(dp[i - k][j], dp[k - 1][j - 1]) + 1);
}
int main()
{
int T, ca, b, m;
cal();
scanf("%d", &T);
while(T--)
{
scanf("%d %d %d", &ca, &b, &m);
printf("%d %d\n", ca, dp[m][b]);
}
}#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int const INF = 0xffffff;
int dp[1005][55];
int main()
{
int T, ca, b, m;
scanf("%d", &T);
while(T--)
{
scanf("%d %d %d", &ca, &b, &m);
for(int i = 0; i <= m; i++)
for(int j = 0; j <= b; j++)
dp[i][j] = INF;
for(int i = 0; i <= b; i++)
dp[0][i] = 0;
for(int i = 1; i <= m; i++)
for(int j = 1; j <= b; j++)
for(int k = 1; k <= i; k++)
dp[i][j] = min(dp[i][j], max(dp[i - k][j], dp[k - 1][j - 1]) + 1);
printf("%d %d\n", ca, dp[m][b]);
}
}原文:http://blog.csdn.net/tc_to_top/article/details/43924867