toj 3761 Egg Problem (好题~~)
2013-11-11 20:01
197 查看
Egg Problem
时间限制(普通/Java):1000MS/3000MS 运行内存限制:65536KByte总提交: 22 测试通过: 7
描述
There is a very interesting problem described as follows:
You are given two eggs.
You have access to a 100-storey building.
An egg that survives a fall can be used again.
A broken egg must be discarded.
The effect of a fall is the same for all eggs.
If an egg breaks when dropped, then it would break if dropped from
a higher window.
If an egg survives a fall then it would survive a shorter
fall.
It is not ruled out that the first-floor windows break eggs, nor
is it ruled out that the 100th-floor windows do not cause an egg to break.
You need to figure out the highest floor an egg can be dropped
without breaking. The question is how many drops you need to make.
Now, I want to know how to solve this problem for any number of eggs and any
storeys. Can you help me?
输入
In the first line there is an integer T (T <= 10000), indicates the number
of test cases.
In each case, there are two integers n and m (1 <= n <= 15, 1 <= m
<= 100000), which are the number of eggs and storeys.
输出
For each case, the output format is “Case c: ans”.
c is the case number start from 1.
ans is the answer of this problem.
样例输入
2 2 100 3 100
样例输出
Case 1: 14 Case 2: 9
题目来源
2011年绍兴市赛
原理:http://blog.sina.com.cn/s/blog_6c813dbd0101bh98.html
推导过程:/article/2801243.html
#include <stdio.h> int dp[20][100010]; void Init(){ for(int i=1; i<=15; i++){ for(int j=1; j<=100000; j++){ if(i == 1) dp[i][j] = j; else if(i == j) dp[i][j] = (1<<i)-1; else if(i >= j) dp[i][j] = dp[j][j]; else if(i < j) dp[i][j] = dp[i-1][j-1] + 1 + dp[i][j-1]; if(dp[i][j]>=100000){ break; } } } } int main() { int T; Init(); scanf("%d", &T); for(int cas=1; cas<=T; cas++){ int n, m; scanf("%d %d", &n, &m); for(int i=1; ; i++){ if(dp [i] >= m){ printf("Case %d: %d\n", cas, i); break; } } } return 0; }
相关文章推荐
- TOJ 3761 Egg Problem
- TOJ 2976
- toj 1709 Incomplete chess boards
- TOJ 1132 Knight Moves BFS求最短路径
- [TOJ]1151. Task Sequences [zoj]3332.Strange Country II --竞赛图的哈密顿路
- TOJ 3622. Perfect Matching
- TOJ 2273 POJ 2818 Making Change DFS C语言
- poj 3761 bubble sort#排列组合
- TOJ 3843 快速排序 折半查找
- TOJ 1037 POJ 2771 LA 3415 Guardian of Decency / 二分图
- TOJ1235最大连续子序列
- TOJ题目分类demo
- TOJ 3407 Parenthesis
- TOJ 4267 An Easy Puz / 深搜
- TOJ 3365 ZOJ 3232 It's not Floyd Algorithm / 强连通分量
- TOJ 2882
- TOJ 2452 Ultra-QuickSort
- TOJ 4002 Palindrome Generator
- TOJ 1885 Triangles
- ZOJ 3761 Easy billiards 月赛E DFS