XTU 1206 Dormitory's Elevator
来源:互联网 发布:学练字的软件 编辑:程序博客网 时间:2024/06/05 17:48
Dormitory's Elevator
Accepted : 52 Submit : 332Time Limit : 1000 MS Memory Limit : 65536 KBProblem 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
13 2 1 12 3
Sample Output
Case 1: 1
#include <iostream>#include <stdio.h>#include <string>#include <cstring>#include <cmath>#include <algorithm>#define N 100009#define ll __int64using namespace std;ll dp[N];//表示从第一层到第n层的最小体力耗费int a[N];int n,m,A,B;//想要少走,那么就要尽可能多的让电梯停下来//如果现在在第i层,那么上一次停靠可以是第i-2,或者第i-3层(因为要多停)int main(){ int t; scanf("%d",&t); for(int ca=1;ca<=t;ca++) { scanf("%d %d %d %d",&n,&m,&A,&B); int ff; memset(a,0,sizeof a); memset(dp,0,sizeof dp); for(int i=0;i<m;i++) { scanf("%d",&ff); a[ff]++; } dp[1]=0; dp[2]=0;//可以停在二楼 //dp[2]=min(A,B)*a[2]; //dp[3]=a[2]*A; for(int i=3;i<=n;i++) { ll tt=1<<30; ll ff=dp[i-2]+min(A,B)*a[i-1];//当上一次是i-2停时,要去i-1的人,可以选择i下或者i-2的时候下,选小的。 if(i-3>0) tt=dp[i-3]+min(2*B*a[i-1]+B*a[i-2],min( A*a[i-1]+A*a[i-2]*2, min(A*a[i-1]+B*a[i-2],A*a[i-2]*2+B*a[i-1]*2 ) ));//当上一次是i-3层停时,那么会有下面四种选择//(i-3->i-1,i-3->i-2); (i->i-1,i->i-2); (i->i-1,i-3->i-2); (i->i-2,i-3->i-1) dp[i]=min(ff,tt); } printf("Case %d: %I64d\n",ca,dp[n]); } return 0;}/*34 8 1 21 1 2 2 3 3 4 4*///2
- XTU 1206 Dormitory's Elevator
- XTU 1206 Dormitory's Elevator
- XTU 1206Dormitory's Elevator(dp)
- XTU Dormitory's Elevator(动态规划)
- XTU 1185 Bob's Problem
- XTU-1185 Bob's Problem
- XTU 1247 Robb's Problem
- XTU 1244 Estrella's Chocolate
- XTU 1245 Lisa’s Puzzle
- xtu-1140 Anti-Goldbach's Conjecture
- HDU's ACM 1008 Elevator
- Dormitory meetting.
- XTU Lisa's Puzzle 裸的字典树
- Elevator
- Elevator
- Elevator
- elevator
- Elevator
- centos6.6 x86_64下安装32位兼容包&openssl 32位
- 离婚率
- hadoop mapreduce 计算平均气温的代码,绝对原创
- java和.net的应用区别
- 如何部署SSM框架(Spring+SpringMVC+MyBatis)到SAE(新浪云服务器)图文教程
- XTU 1206 Dormitory's Elevator
- 【原创】zstack - 协议栈程序精简日志-IO口外部中断试验
- 3、Linux操作系统之操作篇-系统硬件信息查询
- linux 下 安装mysql
- uva 536
- 常见的浏览器兼容性问题
- 安装yum
- CentOS6.4 安装nmon
- [leetcode][hash][math] Happy Number