XTUOJ 1206 Dormitory's Elevator
2015-06-05 19:49
176 查看
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 = 100010; int dp[maxn],des[maxn]; int main(){ int T,n,m,A,B; scanf("%d",&T); for(int t = 1; t <= T; ++t){ memset(dp,0x3f,sizeof dp); memset(des,0,sizeof des); scanf("%d %d %d %d",&n,&m,&A,&B); for(int i = 0,tmp; i < m; ++i){ scanf("%d",&tmp); des[tmp]++; } dp[1] = dp[2] = dp[0] = 0; for(int i = 3; i <= n; ++i){ dp[i] = dp[i-2] + min(A,B)*des[i-1]; int x = min(B,A*2)*des[i-2]; int y = min(B*2,A)*des[i-1]; dp[i] = min(dp[i],dp[i-3] + x + y); } printf("Case %d: %d\n",t,dp ); } return 0; }
View Code
相关文章推荐
- linux shell 判断
- 微信JS-SDK如何使用
- 微信JS-SDK如何使用
- 0-1背包问题,动态规划
- eclipse配置问题汇总
- Hubot插件开发:井字游戏
- 【c++类与对象练习】判断字符串str是否为当前串的子串
- Kmeans++及字典学习和图像分割
- jquery绝对路径
- SourceForge接管网络安全审计软件Nmap的项目
- 大视野在线测评 1010 [HNOI2008]玩具装箱toy (动态规划)
- 组员名单
- 块设备
- 构造函数方法创建Mat对象
- matlab画甘特图
- CentOS安装PostgreSQL数据库
- Java集合框架22课后编程题
- [转]深入分析ConcurrentHashMap
- dietpi请暂时不要升级为jessie
- SQL输出矩阵