湘潭大学oj 1206 Dormitory's Elevator dp
| 27153 | njczy2010 | 1206 | Accepted | 1976 KB | 234 MS | G++ | 1415 B | 2014-09-28 10:01:23 |
真是吐血ac,,,,这么easy的题。。。。。
Dormitory's Elevator |
||
| Accepted : 46 | Submit : 302 | |
| Time Limit : 1000 MS | Memory Limit : 65536 KB | |
Problem DescriptionThe new dormitory has N(1≤N≤100000) floors and M(1≤M≤100000)students. In the new dormitory, in order to save student's time as well as encourage student exercise, the elevator in dormitory will not stop in adjacent floor. So if there are people want to get off the elevator in adjacent floor, one of them must walk one stair instead. Suppose a people go down 1 floor costs A energy, go up 1 floor costs B energy(1≤A,B≤100). Please arrange where the elevator stop to minimize the total cost of student's walking cost.All students and elevator are at floor 1 initially, and the elevator can not godown and can stop at floor 2. InputFirst line contain an integer T, there are T(1≤T≤10) cases. For each case T, there are two lines. First line: The number of floors N(1≤N≤100000), and the number of students M(1≤M≤100000),A,B(1≤A,B≤100) Second line: M integers (2≤A[i]≤N), the student's desire floor. OutputOutput case number first, then the answer, the minimum of the total cost of student's walking cost. Sample Input1 Sample OutputCase 1: 1 Sourcedaizhenyang |
a代表上楼?????? 这点还是没弄清,,,,什么情况。。。。
好吧,,,,我懂了。。。。泪流满面啊。。。。
题解转自:http://blog.csdn.net/y990041769/article/details/39343269
分析:这其实就是一个简单的一维dp,用dp【i】表示从1层上到第 i 层花费的最小的体力。
因为不能在相邻的楼层停留,所以可以从dp【i-2】转移,但这样不是最优的还要从dp【i-3】转移,因为这样的话就可以到达所有的楼层。我们只要在所有的之间dp最优即可。
其他要注意的一个条件是,从dp【i-3】转移时,中间两层的人有四种选择:
1:都上去或都下来
2:上面的上去一层,下面的下来一层
3:上面的下来两层,下面的上去两层,(当时没有考虑到这个,要细心啊)
那么代码就很好写了、
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<queue>
#include<map>
#include<string> #define N 100005
#define M 15
#define mod 10000007
//#define p 10000007
#define mod2 100000000
#define ll long long
#define LL long long
#define maxi(a,b) (a)>(b)? (a) : (b)
#define mini(a,b) (a)<(b)? (a) : (b) using namespace std; int T;
int n,m;
int cnt[N];
int a,b;
int dp[N];
int x;
int ans;
int c; void ini()
{
ans=;
memset(cnt,,sizeof(cnt));
memset(dp,0x3f3f3f3f,sizeof(dp));
scanf("%d%d%d%d",&n,&m,&b,&a);
c=min(a,b);
for(int i=;i<=m;i++){
scanf("%d",&x);
cnt[x]++;
}
dp[]=;
dp[]=;
dp[]=;
dp[]=c*cnt[]; } void solve()
{
int i;
for(i=;i<=n;i++){
dp[i]=min(dp[i-]+c*cnt[i-],dp[i-]+cnt[i-]*min(a,*b)+cnt[i-]*min(b,*a));
}
ans=min(dp[n],dp[n-]+cnt[n]*a);
} void out()
{
printf("%d\n",ans);
} int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
scanf("%d",&T);
for(int ccnt=;ccnt<=T;ccnt++)
// while(T--)
// while(scanf("%d%d",&n,&m)!=EOF)
{
// if(n==0 && m==0) break;
printf("Case %d: ",ccnt);
ini();
solve();
out();
} return ;
}
湘潭大学oj 1206 Dormitory's Elevator dp的更多相关文章
- XTUOJ 1206 Dormitory's Elevator
Dormitory's Elevator Time Limit : 1000 MS Memory Limit : 65536 KB Problem Description The new dorm ...
- ZJK的黑OJ(树的最大独立集)(树形DP)
ZJK的黑OJ zjk开了一家"善良OJ".这其实是家黑OJ.每AC一道题,网站便会自动在电脑上安装一种木马.zjk通过窃取信息获取收益(如网游帐号.OI资料.和KK的照片等等). ...
- Codeforces 983C Elevator dp (看题解)
Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...
- Light OJ 1031 - Easy Game(区间dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ...
- Light OJ 1030 - Discovering Gold(概率dp)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...
- light oj 1422 Halloween Costumes (区间dp)
题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...
- Light OJ 1364 Expected Cards (期望dp,好题)
题目自己看吧,不想赘述. 参考链接:http://www.cnblogs.com/jianglangcaijin/archive/2013/01/02/2842389.html #include &l ...
- light oj 1205 - Palindromic Numbers 数位DP
思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点. 代码如下: #include<iostream> #include<cstdio ...
- Light OJ 1050 - Marbles(概率DP)
题目大意: 一个包裹里有蓝色和红色的弹珠,在这个包裹里有奇数个弹珠,你先走, 你先从背包里随机的拿走一个弹珠,拿走每个弹珠的可能性是一样的.然后Jim从背包里拿走一个蓝色的弹珠,如果没有蓝色的弹珠让J ...
随机推荐
- MINST手写数字识别(二)—— 卷积神经网络(CNN)
今天我们的主角是keras,其简洁性和易用性简直出乎David 9我的预期.大家都知道keras是在TensorFlow上又包装了一层,向简洁易用的深度学习又迈出了坚实的一步. 所以,今天就来带大家写 ...
- 【iview input 回车刷页面bug】input 就一个的时候 有form的时候 回车会刷页面,如果就一个input,可以不要form,或者form里面两个input 将一个input v-show false 就可以了
[iview input 回车刷页面bug]input 就一个的时候 有form的时候 回车会刷页面,如果就一个input,可以不要form,或者form里面两个input 将一个input v-sh ...
- k8s 基础概念和术语
Master k8s里的master指的是集群控制节点,每个k8s集群里需要有一个Master节点来负责整个集群的管理和控制,基本k8s所有控制命令都发给它,它负责整个具体的执行过程,后面执行操作基本 ...
- VC-基础:关于一些符号的意义
GUI应用程序:Graphic User Interface图形 用户 接口 SDI:单文档程序(典型的记事本就是SDI) MID:多文档程序(比如VS2008默认就是多文档的)
- Watch Before You Feel Pressure
Today's assembly is about the start of a journey. 今天的大会是一个旅程的开始. The start of the rest of your lives ...
- MySQL常用表结构查询语句
在我们使用数据库进行查询或者建表时,经常需要查看表结构,下面以employees数据库中的departments表为例进行表结构查询: departments表:(2列9行) +---------+- ...
- PHP 把字符转换为 HTML 实体 - htmlentities() 函数
定义和用法 htmlentities() 函数把字符转换为 HTML 实体. 语法 htmlentities(string,quotestyle,character-set) 参数 描述 string ...
- (21)zabbix创建触发器trigger
1. 创建触发器 了解了什么触发器,接下来看下zabbix触发器怎么创建和配置,方法很简单,请大家往下读,有什么问题请留言. 创建触发器步骤: 点击Configuration(配置) → Hosts( ...
- [图文] Fedora 28 使用 Virt-Manager 制作并优化QCOW2镜像——Windows 10 1709
实验说明: 云计算的发展使得桌面上云,windows 10就必不可少,这一章就如何制作QCOW2镜像文件并优化进行说明. 实验环境: 宿主机系统 :Fedora 28 WorkStation 虚拟 ...
- Vue的响应式规则
对象属性的响应规则 <body> <div id="root"> {{msg}} </div> </body> <script ...