诡异的电梯【Ⅰ】
2017-04-22 16:18
204 查看
诡异的电梯【Ⅰ】
时间限制: 1000ms内存限制: 128000KB
64位整型: Java 类名:
上一题
提交 运行结果 统计 讨论版
下一题
类型:
没有
没有难度 lv.1
lv.2
lv.3 lv.4
lv.5 lv.6
lv.7 lv.8
lv.9 lv.10
搜索数据结构
动态规划STL练习
高精度计算图论
几何数学矩阵计算
入门题目字符串
博弈论
添加
题目描述
新的宿舍楼有 N(1≤N≤100000) 层 andM(1≤M≤100000)个学生. 在新的宿舍楼里, 为了节约学生的时间也为了鼓励学生锻炼身体, 所以规定该宿舍楼里的电梯在相邻的两层之间是不会连续停下(即,如果在第2层停下就不能在第3层停下。).所以,如果有学生在相邻的两层之间要停下, 则其中的一部分学生必须选择走楼梯来代替。规定:一个人走下一层楼梯的花费为A,走上一层楼梯的花费为B。(1≤A,B≤100)现在请你设计一个算法来计算出所有学生走楼梯花费的最小费用总和。 所有的学生一开始都在第一层,电梯不能往下走,在第二层的时候电梯可以停止。
输入
输入有几组数据T。T(1≤T≤10)每组数据有N (1≤N≤100000),M(1≤M≤100000),A,B(1≤A,B≤100)。
接下来有M个数字表示每个学生想要停的楼层。
输出
输出看样例。
样例输入
1 3 2 1 1 2 3
样例输出
Case 1: 1
提示
原题: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.
OUTPUT:
Output case number first, then the answer, the minimum of the total cost of student's walking cost.
/* 分类:dp 来源:NYOJ 诡异的楼梯 思路:d[i]表示走到第i层的最少费用, 状态转移方程d[i]=min(d[i-1]+B*a[i],d[i-2]+mi*a[i-1]); 表示从到第i层,可以有两种选择,如果在第i-1层停了, 那么就不能在第i层停了,所以在第i层的人要从第i-1层走上去, 如果在第i-2层停了,那么第i-1层的人可以选择从第i-2层上去或者从第i层下去, 其中 mi=min(A,B) */ #include<stdio.h> #include<algorithm> #include<string.h> #define maxn 100010 using namespace std; int dp[maxn]; int vis[maxn]; int MIN(int a,int b){ return a<b?a:b; } int main(){ int t,n,m,a,b,i,j,k,test=1; scanf("%d",&t); while(t--){ scanf("%d%d%d%d",&n,&m,&a,&b); memset(dp,0,sizeof(dp)); memset(vis,0,sizeof(vis)); int mi=MIN(a,b); for(i=0;i<m;++i){ scanf("%d",&k);vis[k]++; } printf("Case %d: ",test++); if(n==1||n==2){ printf("0\n"); continue; } for(i=3;i<=n;++i){ dp[i]=MIN(dp[i-1]+a*vis[i],dp[i-2]+MIN(b*vis[i-1],a*vis[i-1])); } printf("%d\n",dp ); } return 0; }
相关文章推荐
- nyoj 1070 诡异的电梯【Ⅰ】【dp】
- 诡异的电梯【Ⅰ】
- 南阳理工acm 1070诡异的电梯【Ⅰ】(动态规划)
- NYOJ-诡异的电梯【Ⅰ】-(动态规划)
- NYOJ 题目1070 诡异的电梯【Ⅰ】(dp)
- NYOJ 诡异的电梯 && nyoj 1204 魔法少女
- NYOJ 1070 诡异的电梯【Ⅰ】 DP
- nyist 1070 诡异的电梯【Ⅰ】(比较好的DP)
- NYOJ 1070 诡异的电梯【Ⅰ】
- nyoj 诡异的电梯【Ⅰ】 1070 (DP) 好题
- nyoj1070诡异的电梯【Ⅰ】【dp】
- 数塔-诡异的电梯
- NYOJ-1070-诡异的电梯[Ⅰ]
- nyoj 1070 诡异的电梯 简单dp
- 诡异的电梯【Ⅰ】
- NYOJ-1070诡异的电梯【Ⅰ】
- 恐怖经历之诡异电梯
- NYIST 1070 诡异的电梯【Ⅰ】
- nyoj 1070 诡异的电梯【Ⅰ】 动态规划
- NYOJ - 1070 - 诡异的电梯【Ⅰ】(动态规划)