首页 技术 正文
技术 2022年11月20日
0 收藏 385 点赞 3,896 浏览 1429 个字

Dormitory’s Elevator

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

解题:动态规划,同NYIST的诡异的电梯

 #include <bits/stdc++.h>
using namespace std;
const int maxn = ;
int dp[maxn],des[maxn];
int main(){
int T,n,m,A,B;
scanf("%d",&T);
for(int t = ; t <= T; ++t){
memset(dp,0x3f,sizeof dp);
memset(des,,sizeof des);
scanf("%d %d %d %d",&n,&m,&A,&B);
for(int i = ,tmp; i < m; ++i){
scanf("%d",&tmp);
des[tmp]++;
}
dp[] = dp[] = dp[] = ;
for(int i = ; i <= n; ++i){
dp[i] = dp[i-] + min(A,B)*des[i-];
int x = min(B,A*)*des[i-];
int y = min(B*,A)*des[i-];
dp[i] = min(dp[i],dp[i-] + x + y);
}
printf("Case %d: %d\n",t,dp[n]);
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,033
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,520
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,368
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,148
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,781
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,862