lightoj 1381 - Scientific Experiment dp
1381 - Scientific Experiment
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://www.lightoj.com/volume_showproblem.php?problem=1381
Description
John wants to be a scientist. A first step of becoming a scientist is to perform experiment. John has decided to experiment with eggs. He wants to compare the hardness of eggs from different species. He has decided to use a nearby large multi-storied building for this purpose. For each species he will try to find the highest floor from which he can drop the egg and it will not break. The building has (n+1) floors numbered from 0 to n. John has a book from which he knows that
- If an egg is dropped from the topmost floor, it will surely break.
- If an egg is dropped from floor 0, it will not break.
- The eggs of same species are of same strength. That means if any egg breaks when dropped from the kth floor; all the eggs of that species will break if dropped from kth floor.
- If an egg is unbroken after dropping it from any floor, it remains unharmed, that means the strength of the egg remains same.
Unfortunately John has a few problems:
- He can only carry one egg at a time.
- He can buy eggs from a shop inside the building and an egg costs x cents.
- To enter the building he has to pay y cents if he has no egg with him and z cents if he carries an egg with him.
- After dropping an egg, John must go outside the building to check whether it's broken or not.
- He does not want to waste any egg so he will not leave any unbroken egg on the ground. But if an egg is broken, he leaves it there.
- If he has an intact egg at the end, he can sell it for x/2 cents. He does not need to enter the building to sell the egg.
These problems are not going to tame John's curious mind. So he has decided to use an optimal strategy and minimize his cost in worst case. As John is not a programmer, he asked your help.
Input
Input starts with an integer T (≤ 50), denoting the number of test cases.
Each case starts with a line containing four integers n x y z as described in the statement. You may assume that 1 < n ≤ 1000 and 1 ≤ x, y, z ≤ 105 and x is even.
Output
For each test case, print the case number and the minimized worst case cost.
Sample Input
7
4 2 998 1000
16 2 1000 1000
16 1000 1 1
4 1000 1 1
7 2 2 2
9 2 1 100
11 2 100 1
Sample Output
Case 1: 2000
Case 2: 4008
Case 3: 1015
Case 4: 1003
Case 5: 10
Case 6: 24
Case 7: 111
HINT
For case 1, John knows that the egg will break if dropped from 4th floor, but will not break if dropped from 0th floor. An optimal solution may be
- John enters the building without any egg (¢998).
- John buys an egg (¢2).
- John drops an egg from 2nd floor. John goes out and checks the egg.
- If it breaks,
- i. John again enters the building without any egg (¢998) and buys an egg there ¢2.
- ii. He drops the egg from 1st floor.
- If it does not break then answer to his problem is 1 and he can sell the egg for ¢1. So his final cost in ¢1999.
- If it breaks then the answer to his problem is 0th floor and his final cost is ¢2000.
- If it breaks,
- If it does not break
- i. John enters the building with the egg (¢1000).
- ii. He drops it from 3rd floor.
- If it does not break then answer to his problem is 3 and he can sell the egg for ¢1. So his final cost in ¢1999.
- If it breaks then the answer to his problem is 2 and final cost is ¢2000.
So, using this strategy, his worst case cost is ¢2000.
题意
一个评估蛋的硬度方法是测量蛋从多高摔下来会碎。现在佳佳想以楼层高度作为考量依据评估蛋的 硬度。如果蛋从i楼上掉下来会碎,而i-1不会,那么蛋的硬度为i。高为n层的实验楼里面有蛋卖,一个X元。佳佳开始没有蛋,并且他只能随身携带一个蛋, 不带蛋进楼需要Y元,带蛋需要Z元,做完试验之后如果还有一个蛋,可以卖掉得X/2元(卖蛋不需要进楼)。佳佳把鸡蛋扔出去后,会出楼检查蛋的情况。如果 蛋扔下后没有碎掉,佳佳一定会把蛋捡起,然后进楼,如蛋碎掉了,佳佳就不会管它。 佳佳想知道在最糟糕的情况下,测出蛋的硬度最少需要花费多少钱。
题解:
dp[i]表示在楼层高度为i的情况下,检测出碎蛋的位置的最小最差花费是多少
然后转移就好,注意这个dp[i]只和楼层高度有关!
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 200001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
//const int inf=0x7fffffff; //нчоч╢С
const int inf=0x3f3f3f3f;
/* inline void P(int x)
{
Num=0;if(!x){putchar('0');puts("");return;}
while(x>0)CH[++Num]=x%10,x/=10;
while(Num)putchar(CH[Num--]+48);
puts("");
}
*/
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//**************************************************************************************
ll dp[maxn];
ll d1,d2;
int n,x,y,z;
int main()
{
int t=read();
for(int cas=;cas<=t;cas++)
{
n=read(),x=read(),y=read(),z=read();
dp[]=dp[]=;
for(int i=;i<=n;i++){
dp[i]=inf;
for(int j=;j<i;j++)
{
d1=dp[j]+x+y;
d2=dp[i-j]+z;
if(i-j==)
d2=y+x/;
dp[i]=min(dp[i],max(d1,d2));
}
}
printf("Case %d: %lld\n",cas,dp[n]);
}
}
lightoj 1381 - Scientific Experiment dp的更多相关文章
- lightoj 1032 二进制的dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1032 #include <cstdio> #include <cst ...
- lightOJ 1017 Brush (III) DP
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1017 搞了一个下午才弄出来,,,,, 还是线性DP做的不够啊 看过数据量就知道 ...
- LightOJ 1068 Investigation (数位dp)
problem=1068">http://www.lightoj.com/volume_showproblem.php?problem=1068 求出区间[A,B]内能被K整除且各位数 ...
- Lightoj 1044 - Palindrome Partitioning (DP)
题目链接: Lightoj 1044 - Palindrome Partitioning 题目描述: 给一个字符串,问至少分割多少次?分割出来的子串都是回文串. 解题思路: 先把给定串的所有子串是不 ...
- lightoj 1084 - Winter(dp+二分+线段树or其他数据结构)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1084 题解:不妨设dp[i] 表示考虑到第i个点时最少有几组那么 if a[i ...
- (LightOJ 1030)期望dp
You are x N grid. Each cell of the cave can contain any amount of gold. Initially you are . Now each ...
- lightoj 1027 简单概率dp
题目链接:http://lightoj.com/volume_showproblem.php?problem=1027 #include<cstdio> #include<cstri ...
- URAL 1203 Scientific Conference dp?贪心
题目:click here 分明就是贪心怎么会在dp的专题 #include <bits/stdc++.h> using namespace std; typedef unsigned l ...
- LightOJ 1030 【概率DP求期望】
借鉴自:https://www.cnblogs.com/keyboarder-zsq/p/6216762.html 题意:n个格子,每个格子有一个值.从1开始,每次扔6个面的骰子,扔出几点就往前几步, ...
随机推荐
- Spring Boot企业级博客系统实战视频教程
欢迎关注我的微信公众号:"Java面试通关手册" 回复关键字" springboot "免费领取(一个有温度的微信公众号,期待与你共同进步~~~坚持原创,分享美 ...
- 有关mysql的innodb_flush_log_at_trx_commit参数【转】
一.参数解释 0:log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下在事务提交的时候,不会主动触发写入磁盘的操作. 1:每次事务 ...
- 338.Counting Bits---位运算---《剑指offer》32
题目链接:https://leetcode.com/problems/counting-bits/description/ 题目大意:求解从0到num的所有数的二进制表示中所有1的个数. 法一:暴力解 ...
- docker简单介绍(资料收集总结)
[前言] 首先,感谢我的leader总是会问我很多技术的基本资料,让我这个本来对于各种技术只知道操作命令不关注理论知识的人,开始重视理论资料. 关于docker的操作步骤等等,都是之前学习的,现在补上 ...
- [ python ] FTP作业进阶
作业:开发一个支持多用户在线的FTP程序 要求: 用户加密认证 允许同时多用户登录 每个用户有自己的家目录 ,且只能访问自己的家目录 对用户进行磁盘配额,每个用户的可用空间不同 允许用户在ftp se ...
- windows下安装多个mysql
1.正常安装mysql5.1.33 安装服务名为mysql3306 安装目录d:\mysql5.1\3306 安装完成后,关闭服务 ① 复制安装文件 将默认安装目录C:\Documents and S ...
- POJ 3186Treats for the Cows(区间DP)
题目链接:http://poj.org/problem?id=3186 题目大意:给出的一系列的数字,可以看成一个双向队列,每次只能从队首或者队尾出队,第n个出队就拿这个数乘以n,最后将和加起来,求最 ...
- mac pro上安装docker
1.进入一下地址进行下载docker https://download.docker.com/mac/stable/Docker.dmg 进入后进行下载后进行安装 2.将其拖动到Appliaction ...
- MySql学习笔记——存储函数
在学习完存储过程后,今天主要回顾一下mysql中的存储函数的知识. 函数与存储过程的区别 首先,存储函数也是过程式对象之一,与存储过程相似.它们都是由SQL和过程式语句组成的代码片断,并且可以从应用程 ...
- lr11_Vugen_Genrial Options选项介绍:
lr11_Vugen_Genrial Options选项介绍: