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. CAD交互绘制mcdbsolid对象(网页版)

    主要用到函数说明: _DMxDrawX::DrawSolid 绘McDbSolid对象.详细说明如下: 参数 说明 DOUBLE dX1 第一个点X DOUBLE dY1 第一个点Y DOUBLE d ...

  2. Android之父Andy Rubin:被乔布斯羡慕嫉妒的天才

    今年中国掀起一股“苹果热”,智能手机iPhone.平板电脑iPad遭疯抢,一度卖断货.然而,令许多人意想不到的是,在“苹果”的老家——美国市场,智能手机中卖得最火的并不是iPhone,而是Androi ...

  3. WINDOWS-基础:_T

    _T("")是一个宏,定义于tchar.h下. #define __T(x) L ## x #define _T(x) __T(x) 作用 他的作用是让你的程序支持Unicode编 ...

  4. 选择法数组排序参考(Java)

    package com.swift; public class Xuanze { public static void main(String[] args) { int[] arr= {28,2,3 ...

  5. 【Java_基础】java中static与final关键字的区别

    1.static关键字 经static关键字修饰的成员被该类的所有对象所共享,任意一对象对静态变量的修改其它对象都是可见的.通常通过类名来引用static成员.类加载的连接阶段将会为静态成员变量在jv ...

  6. docker的网络(进阶)

    overlay网络 overlay网络驱动程序会在多个docker守护程序(即多个主机上的docker守护程序)之间创建分布式网络.该网络(overlays)位于特定于主机的网络之上,允许连接到它的容 ...

  7. tkinter学习-布局管理器

    阅读目录 pack 是按照添加顺序排列的组件 grid  是按照行/列形式排序的组件 place 允许程序员指定组件的大小和位置 pack: 说明:适用于少量的简单的组件的排列 fill:这个选项是告 ...

  8. html2canvas.js网页截图功能

    需求:将网页生成图片,用户自行长按图片进行保存图片,再分享朋友圈.其中,都可识别图中的二维码.(二维码过小会识别不出) 首先,先来科普一下微信网页识别二维码原理:截屏识别,当客户端发现用户在网页的im ...

  9. perl中foreach(二)

    本文和大家重点讨论一下Perl foreach命令的用法,Perl foreach循环中控制变量的值会被Perl自动保存和恢复.当循环进行时,是没有办法改变其值的.循环结束时,变量的值会回到循环开始前 ...

  10. Linux配置使用SSH Key登录并禁用root密码登录(替换同理)

    Linux系统大多说都支持OpenSSH,生成公钥.私钥的最好用ssh-keygen命令,如果用putty自带的PUTTYGEN.EXE生成会不兼容OpenSSH,从而会导致登录时出现server r ...