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 Description

The 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.

Input

First 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.

Output

Output case number first, then the answer, the minimum of the total cost of student's walking cost.

Sample Input

1
3 2 1 1
2 3

Sample Output

Case 1: 1

Source

daizhenyang

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的更多相关文章

  1. XTUOJ 1206 Dormitory's Elevator

    Dormitory's Elevator Time Limit : 1000 MS   Memory Limit : 65536 KB Problem Description The new dorm ...

  2. ZJK的黑OJ(树的最大独立集)(树形DP)

    ZJK的黑OJ zjk开了一家"善良OJ".这其实是家黑OJ.每AC一道题,网站便会自动在电脑上安装一种木马.zjk通过窃取信息获取收益(如网游帐号.OI资料.和KK的照片等等). ...

  3. Codeforces 983C Elevator dp (看题解)

    Elevator 怎么今天写啥题都不会写啊, 我是傻了吗.. 把电梯里面四个人的目标点当作状态, 然后暴力转移. #include<bits/stdc++.h> #define LL lo ...

  4. Light OJ 1031 - Easy Game(区间dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1031 题目大意:两个选手,轮流可以从数组的任意一端取值, 每次可以去任意个但仅 ...

  5. Light OJ 1030 - Discovering Gold(概率dp)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的 ...

  6. light oj 1422 Halloween Costumes (区间dp)

    题目链接:http://vjudge.net/contest/141291#problem/D 题意:有n个地方,每个地方要穿一种衣服,衣服可以嵌套穿,一旦脱下的衣服不能再穿,除非穿同样的一件新的,问 ...

  7. Light OJ 1364 Expected Cards (期望dp,好题)

    题目自己看吧,不想赘述. 参考链接:http://www.cnblogs.com/jianglangcaijin/archive/2013/01/02/2842389.html #include &l ...

  8. light oj 1205 - Palindromic Numbers 数位DP

    思路:搜索的时候是从高位到低位,所以一旦遇到非0数字,也就确定了数的长度,这样就知道回文串的中心点. 代码如下: #include<iostream> #include<cstdio ...

  9. Light OJ 1050 - Marbles(概率DP)

    题目大意: 一个包裹里有蓝色和红色的弹珠,在这个包裹里有奇数个弹珠,你先走, 你先从背包里随机的拿走一个弹珠,拿走每个弹珠的可能性是一样的.然后Jim从背包里拿走一个蓝色的弹珠,如果没有蓝色的弹珠让J ...

随机推荐

  1. UVA - 11082 Matrix Decompressing (最大流,技巧)

    很经典的网络流模型,行编号和列编号分别看成一个点,行和列和分别看出容量,一个点(x,y)看出是一条边,边的容量下界是1,所以先减去1,之后在加上就好了. 建图的时候注意分配好编号,解从残留网络中的边找 ...

  2. 机器学习之 PCA (二)

    参考  http://www.cnblogs.com/frombeijingwithlove/p/5931872.html

  3. 换个语言学一下 Golang (5)——运算符

    运算符用于在程序运行时执行数学或逻辑运算. Go 语言内置的运算符有: 算术运算符 关系运算符 逻辑运算符 位运算符 赋值运算符 其他运算符 接下来让我们来详细看看各个运算符的介绍. 算术运算符 下表 ...

  4. Javascript根据指定下标或对象删除数组元素

    删除数组元素在工作中经常会用到,本文讲解一下Javascript根据下标删除数组元素的方法,需要了解的朋友可以参考下 将一下代码放在全局js文件中: Js代码 /** *删除数组指定下标或指定对象 * ...

  5. jQuery绑定动态元素的点击事件无效

    之前就一直受这个问题的困扰,在写ajax加载数据的时候发现,后面追加进来的demo节点元素,失去了之前的点击事件.为什么点击事件失效,我们该怎么去解决呢?那么,我们通过下面的示例简单说明. 示例如下: ...

  6. 洛谷 P3958 奶酪

    谨以此题来纪念我爆炸的NOIp2017 这个题虽然很多人说是并查集,但是搜索也是毫无压力的,考场搜索细节写挂,爆了个不上不下的80分.今天无意看到这道题,终于AC 首先这道题要考虑一下精度问题,虽然出 ...

  7. Bootstrap 网页乱码

    问题:今天早上在实践bootstrap的时候,用EditPlus写代码,标签中包含了中文.在浏览器解析的时候中文部分生成的乱码.但是网页部分已经声明了使用utf-8的编码方式. 解决:网页字体正常显示 ...

  8. 如何用纯 CSS 创作一个菱形 loader 动画

    效果预览 在线演示 按下右侧的"点击预览"按钮可以在当前页面预览,点击链接可以全屏预览. https://codepen.io/comehope/pen/eKzjqK 可交互视频教 ...

  9. 面向对象之多态,property

    多态: 同一种事物有多种状态 多态性: 在不考虑对象具体类型的前提下直接调用对象下的方法 静态多态性和动态多态性 静态多态性:都可以进行+操作 动态多态性:不考虑对象具体类型调用方法 多态的好处: ① ...

  10. Django中模板查找路径配置