toj 3761 Egg Problem (好题~~)
Egg Problem
总提交: 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
题目来源
原理:http://blog.sina.com.cn/s/blog_6c813dbd0101bh98.html
推导过程:http://blog.csdn.net/joylnwang/article/details/6769160
#include <stdio.h>
int dp[][];
void Init(){
for(int i=; i<=; i++){
for(int j=; j<=; j++){
if(i == ) dp[i][j] = j;
else if(i == j) dp[i][j] = (<<i)-;
else if(i >= j) dp[i][j] = dp[j][j];
else if(i < j) dp[i][j] = dp[i-][j-] + + dp[i][j-];
if(dp[i][j]>=){
break;
}
}
}
}
int main()
{
int T;
Init();
scanf("%d", &T);
for(int cas=; cas<=T; cas++){
int n, m;
scanf("%d %d", &n, &m);
for(int i=; ; i++){
if(dp[n][i] >= m){
printf("Case %d: %d\n", cas, i);
break;
}
}
}
return ;
}
toj 3761 Egg Problem (好题~~)的更多相关文章
- 2 Egg Problem
继续我们的推理问题之旅,今天我们要对付的是一个Google的面试题:Two Egg Problem. 我们开始吧! No.2 Google Interview Puzzle : 2 Egg Prob ...
- 【BZOJ1000】A+B Problem ★BZOJ1000题达成★
[BZOJ1000]A+B Problem Description 输入两个数字,输出它们之和 Input 一行两个数字A,B(0<=A,B<100) Output 输出这两个数字之和 S ...
- hdu-5867 Water problem(水题)
题目链接: Water problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Othe ...
- Poj1207 The 3n + 1 problem(水题(数据)+陷阱)
一.Description Problems in Computer Science are often classified as belonging to a certain class of p ...
- Codeforces - 1194B - Yet Another Crosses Problem - 水题
https://codeforc.es/contest/1194/problem/B 好像也没什么思维,就是一个水题,不过蛮有趣的.意思是找缺黑色最少的行列十字.用O(n)的空间预处理掉一维,然后用O ...
- HDU 5475:An easy problem 这题也能用线段树做???
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- HDOJ(HDU) 2123 An easy problem(简单题...)
Problem Description In this problem you need to make a multiply table of N * N ,just like the sample ...
- codeforces 340C Tourist Problem(公式题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud Tourist Problem Iahub is a big fan of tou ...
- HDU 5832 A water problem 水题
A water problem 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
随机推荐
- Linux.vim.多行复制、删除、剪切
复制: //单行复制+粘贴 yy + p:复制光标所处当前行, 敲p粘贴在光标处. //多行复制+粘贴 n + yy + p:复制光标所在行起以下n行(含当前行), 敲yy复制光标所处当前行, 敲p粘 ...
- matplotlib 折线图
1.基本要点 # 导入模块 from matplotlib import pyplot as plt # x轴数据 x = range(2, 26, 2) # y轴数据 y = [15, 13, 14 ...
- kindeditor富文本编译器
一.网址 kindeditor.net/about.php 二.编辑器的使用,看官方文档 三.常用初始化参数 1.resizeType2或1或0,2时可以拖动改变宽度和高度,1时只能改变高度,0时不能 ...
- Application run failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name
目前有发现的两种情况 第一种:是在继承jpa的时候检查实体类@id和@Entity引进的包是否是 import javax.persistence.Id imprt javax.persistence ...
- 学习 lind api 十月 第一弹
step one 我们来看一下代码的结构
- Java容器解析系列(17) LruCache详解
在之前讲LinkedHashMap的时候,我们说起可以用来实现LRU(least recent used)算法,接下来我看一下其中的一个具体实现-----android sdk 中的LruCache. ...
- swoole(PHP异步网络通信引擎)的结构和运行流程
swoole结构说明和运行流程 主要分为三个部分: 1.Master:swoole的主进程 处理swoole核心的事件驱动, 它包含多个线程(蓝色Reactor), 所有事件的监听都在Reactor实 ...
- Python zmq的三种简单模式
ZMQ (以下 ZeroMQ 简称 ZMQ)是一个简单好用的传输层,像框架一样的一个 socket library,他使得 Socket 编程更加简单.简洁和性能更高. 是一个消息处理队列库,可在多个 ...
- composer实践总结
composer composer 概述 FIG 最初由几位知名 PHP 框架开发者发起,在吸纳了许多优秀的大脑和强健的体魄后,提出了 PSR-0 到 PSR-4 五套 PHP 非官方规范: PSR- ...
- Selenium(一):元素定位
一.Selenium 8种定位方式 baidu.html <form id="form" name="f" action="/s" c ...