XTUOJ 1206 Dormitory's Elevator

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的诡异的电梯

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 const int maxn = 100010;
 4 int dp[maxn],des[maxn];
 5 int main(){
 6     int T,n,m,A,B;
 7     scanf("%d",&T);
 8     for(int t = 1; t <= T; ++t){
 9         memset(dp,0x3f,sizeof dp);
10         memset(des,0,sizeof des);
11         scanf("%d %d %d %d",&n,&m,&A,&B);
12         for(int i = 0,tmp; i < m; ++i){
13             scanf("%d",&tmp);
14             des[tmp]++;
15         }
16         dp[1] = dp[2] = dp[0] = 0;
17         for(int i = 3; i <= n; ++i){
18             dp[i] = dp[i-2] + min(A,B)*des[i-1];
19             int x = min(B,A*2)*des[i-2];
20             int y = min(B*2,A)*des[i-1];
21             dp[i] = min(dp[i],dp[i-3] + x + y);
22         }
23         printf("Case %d: %d\n",t,dp[n]);
24     }
25     return 0;
26 }

XTUOJ 1206 Dormitory's Elevator

时间: 2024-10-29 19:13:37

XTUOJ 1206 Dormitory's Elevator的相关文章

湘潭大学oj 1206 Dormitory&#39;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 Description The new dormitory has N(1≤N≤10000

XTU 1206 Dormitory&#39;s Elevator

Dormitory's Elevator Accepted : 52   Submit : 332 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 a

nyoj 1070 诡异的电梯【Ⅰ】【dp】

题目:nyoj 1070 诡异的电梯[Ⅰ] 这个题目源自湘潭大学oj 1206 Dormitory's Elevator 是当时比赛的题目,题目都没有读清楚啊. 分析:这其实就是一个简单的一维dp,用dp[i]表示从1层上到第 i 层花费的最小的体力. 因为不能在相邻的楼层停留,所以可以从dp[i-2]转移,但这样不是最优的还要从dp[i-3]转移,因为这样的话就可以到达所有的楼层.我们只要在所有的之间dp最优即可. 其他要注意的一个条件是,从dp[i-3]转移时,中间两层的人有四种选择: 1:

hzau 1206 MathematicalGame

1206: MathematicalGame Time Limit: 2 Sec  Memory Limit: 1280 MBSubmit: 124  Solved: 15[Submit][Status][Web Board] Description Xiao Ming likes to play mathematical games very much. One day, he gets a sequence of n positive integers. XOR (l , r) is def

Elevator

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The highest building in our city has only one elevator. A request list is made up with N positive numbers. The numbers denote at which floors the elevator will s

hdu 1008 elevator

#include<iostream> #include<stdio.h> #include<math.h> #include<algorithm> using namespace std; int main() { int n; while(~scanf("%d",&n)&&n!=0) { int a,b; a=0; int ans=0; for(int i=0;i<n;i++) { scanf("

BNUOJ 1206 A Plug for UNIX

A Plug for UNIX Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 108764-bit integer IO format: %lld      Java class name: Main You are in charge of setting up the press room for the inaugural meeting of the Un

poj 2392 Space Elevator (多重背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8110   Accepted: 3843 题目大意  :一群牛要上天  用一些石块堆塔  给出石块的种类  及其每个种类的数量 和该种石块能出现的最高高度  和每种石块的数量 求怎么摆放才能堆得最高 多重背包模板题.... 将所有石块排序  把高度低的放下面 #include<iostream> #include<cstdio>

POJ2392Space Elevator(贪心+背包)

Space Elevator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9970   Accepted: 4738 Description The cows are going to space! They plan to achieve orbit by building a sort of space elevator: a giant tower of blocks. They have K (1 <= K <