hdu 3738 The Sweat Shop(dp)
来源:互联网 发布:血色衣冠4.0数据出错 编辑:程序博客网 时间:2024/05/16 07:11
The Sweat Shop
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 35 Accepted Submission(s): 15
Problem Description
Many people spend thier lives in sweat shop in China. The boss of one of the famous sweat shop, GXX, is considering about the employment plan of her company.
He already knows that in the next N days, how many worker are needed for this day's work, a[i]. In additional, he will spend x yuan on recruit a worker, y yuan on fire a worker. If a worker spend a day on work in his company, GXX must pay z yuan for the wages per day.
GXX has no work before the first day and he decide to fire all the workers after these N days. Now comes to the question, how much he will pay on the employment plan in minimum.
He already knows that in the next N days, how many worker are needed for this day's work, a[i]. In additional, he will spend x yuan on recruit a worker, y yuan on fire a worker. If a worker spend a day on work in his company, GXX must pay z yuan for the wages per day.
GXX has no work before the first day and he decide to fire all the workers after these N days. Now comes to the question, how much he will pay on the employment plan in minimum.
Input
The first line contains only one integer T, denoting the number of test cases.
For each test cases, the first line contains only one integer N, denoting the number of days. (1 <= N <= 100000)
The next line contains three integers, x, y and z, denoting the amount of spend on recruit, fire a worker, and the daily salary of a worker. (1 <= x,y,z <= 100000)
The third line contains N integers, a[i], denoting the minimum number of workers needed for the i-th day. (1 <= a[i] <= 100000)
For each test cases, the first line contains only one integer N, denoting the number of days. (1 <= N <= 100000)
The next line contains three integers, x, y and z, denoting the amount of spend on recruit, fire a worker, and the daily salary of a worker. (1 <= x,y,z <= 100000)
The third line contains N integers, a[i], denoting the minimum number of workers needed for the i-th day. (1 <= a[i] <= 100000)
Output
For each test cases, output a single number denoting the minimum amount GXX should spend on employment plan.
Sample Input
1310 10 12 1 2
Sample Output
46
Author
永远的魔灵
Source
ACMDIY第二届群赛
#include <stdio.h>#include <string.h>#include <math.h>#include <stdlib.h>#define N 100010int n;__int64 a[N], x, y, z;int q[N], ed;__int64 min(__int64 a,__int64 b ){ return a<b?a:b; }void solve() { __int64 res = a[0] * x + a[n - 1] * y; for (int i = 0; i < n; ++i) { res += a[i] * z; if(i) { if (a[i - 1] > a[i]) res += (a[i - 1] - a[i]) * y; else res += (a[i] - a[i - 1]) * x; } } ed = 0; q[ed++] = 0; for (int i = 1; i < n; ++i) { if (a[q[ed - 1]] >= a[i]) q[ed++] = i; else { while (ed > 1 && a[q[ed - 1]] < a[i]) { --ed; /* t是解雇工人的数目 , tmp---是留着这个工人省钱还是解雇这个工人省的钱 ?? */ __int64 tmp, t = min(a[i], a[q[ed - 1]]) - a[q[ed]]; if ((tmp = (x + y - (i - q[ed - 1] - 1) * z) * t) > 0) { res -= tmp; //printf("\n........\nq[ed]=%d l=%d r=%d tmp=%d\n",q[ed],q[ed - 1],i,tmp); } } if (a[q[ed - 1]] <= a[i]) --ed; q[ed++] = i; } } printf("%I64d\n", res);}int main() { freopen("in.txt","r",stdin); freopen("out.txt","w",stdout); int cas; scanf("%d", &cas); while (cas--) { scanf("%d", &n); scanf("%I64d%I64d%I64d", &x, &y, &z); for (int i = 0; i < n; ++i) { scanf("%I64d", &a[i]); } solve(); } return 0;}
- hdu 3738 The Sweat Shop(dp)
- hdu 3738 The Sweat Shop 单调栈加贪心思想
- hdu 1355 The Peanuts(DP)
- hdu 1709 The Balance (dp)
- POJ1157LITTLE SHOP OF FLOWERS【dp】
- RMRC2016 G:Flow Shop (DP)
- hdu 1561 The more, The Better DP
- Don't Sweat The Small Stuff…and It' All Small Stuff
- C++ Coding Standards ---- Item0 : Don's sweat the small stuff.(Or : Know what not to standardize)
- hdu 3006 the number of set 【dp】
- hdu 4151 The Special Number (DP)
- HDU 1133 Buy the Ticket(DP)
- hdu - 4314 - Save the dwarfs - dp
- hdu - 4328 - Cut the cake - dp
- hdu 3496 Watch The Movie(DP)
- HDU 1081 To The Max 二维dp
- hdu 1081 To The Max 基础dp
- HDU 1081 To The Max ---二维dp
- c++学习书籍推荐 .
- XML(三)--java开发常用API
- MySQL优化总结
- Changing machine name by setting registry
- Selenium 中文API
- hdu 3738 The Sweat Shop(dp)
- CCD和CMOS摄像头的区别
- DXUT框架 学习笔记
- Android(SpreadTurm)开锁前设置一个亮度,解锁后再设置一个亮度
- Linux ALSA声卡驱动之三:PCM设备的创建
- ASP.NET上传文件的三种基本方法
- Highcharts应用指南(从零开始配置highcharts)
- 字节、字、位、比特,四者之间的关系
- iOS面试题汇总 (1)