湘潭大学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 ...
随机推荐
- Python数据结构和类型--解压序列赋值多个变量
Python数据结构和类型 1.1 解压序列赋值给多个变量 现在有一个包含N个元素的元组或者是序列,怎样将它里面的值解压后同时赋值给N个变量? 解决思路:先通过简单的解压赋值给多个变量,前提是变量的数 ...
- ZOJ-1360 || POJ-1328——Radar Installation
ZOJ地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=360 POJ地址:http://poj.org/problem?id ...
- C# IsNullOrEmpty与IsNullOrWhiteSpace
IsNullOrEmpty:非空非NULL判断 IsNullOrWhiteSpace:非空非NULL非空格判断 后者优于前者 if (!string.IsNullOrWhiteSpace(valueE ...
- Java--泛型理解和使用 (List<String> list = new ArrayList<String>(); )
List<String> list = new ArrayList<String>(); 第一次看到这行代码是一头雾水,查了好久才弄清楚这是什么东西,怎么用,所以记录下来,方便 ...
- ZJOI2018游记Round2
Day0 趁着空档还溜回班上了一节物理课:瓢泼之中在9:00赶往余姚,车程3h+-- 中饭在一家饭馆,味道海星. 晚上和ykh,chj,xzt溜去吃一鸣和烧烤.一鸣不错,烧烤的话我因为口腔溃疡没怎么吃 ...
- 使Linux支持exFAT和NTFS格式的磁盘
Linux支持exFAT和NTFS Linux系统默认可以自动识别到fat32格式的盘,但fat32支持的文件不能大于4G,所以只能将移动硬盘和U盘格式化为NTFS和exFAT这两种格式的,对于U盘最 ...
- Mac OSX: 有线共享WiFi
首先连上有线 系统偏好设置->网络->点击左侧WiFi,再点击右下角[高级] 勾选[创建电脑对电脑网络],然后单击[好] 在顶部菜单栏击WiFi图标,如果WiFi未打开,则单击打开,如果已 ...
- python爬虫入门一:爬虫基本原理
1. 什么是爬虫 爬虫就是请求网站并提取数据的自动化程序 2. 爬虫的基本流程 1)发送请求 通过HTTP库向目标站点发送请求,即发送一个Request. 请求可以包含额外的headers等信息,等待 ...
- python爬虫入门六:Selenium库
在我们爬取网页过程中,经常发现我们想要获得的数据并不能简单的通过解析HTML代码获取,这些数据是通过AJAX异步加载方式或经过JS渲染后才呈现在页面上显示出来. selenuim是一种自动化测试工具, ...
- (转)编写高质量的OC代码
点标记语法 属性和幂等方法(多次调用和一次调用返回的结果相同)使用点标记语法访问,其他的情况使用方括号标记语法. 良好的风格: view.backgroundColor = [UIColor or ...