Employment Planning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5151    Accepted Submission(s): 2208

Problem Description
A project manager wants to determine the number of the workers needed in every month. He does know the minimal number of the workers needed in each month. When he hires or fires a worker, there will be some extra cost. Once a worker is hired, he will get the
salary even if he is not working. The manager knows the costs of hiring a worker, firing a worker, and the salary of a worker. Then the manager will confront such a problem: how many workers he will hire or fire each month in order to keep the lowest total
cost of the project. 
 
Input
The input may contain several data sets. Each data set contains three lines. First line contains the months of the project planed to use which is no more than 12. The second line contains the cost of hiring a worker, the amount of the salary, the cost of firing
a worker. The third line contains several numbers, which represent the minimal number of the workers needed each month. The input is terminated by line containing a single '0'.
 
Output
The output contains one line. The minimal total cost of the project.
 
Sample Input
3
4 5 6
10 9 11
0
 
Sample Output
199
 

本题的意思是给出给出雇佣一个工人的钱,工人每月的钱,和解雇工人的钱,和每月所需工人,算出最小花费。

想法就是把每月雇佣多少个工人的费用全保存下来,for跑一遍找出得到上月雇佣j个到本月的雇佣k个工人所需的最小花费,第一个月特殊处理

这题没给每月工人个数,我那100做过了

代码如下

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
#define inf 0x3f3f3f3f int dp[15][110];
int e,f,s;
int a[15]; int main()
{
int n;
int mn;
while(~scanf("%d",&n)&&n)
{
scanf("%d%d%d",&e,&s,&f);
for(int i=1; i<=n; i++)
{
scanf("%d",&a[i]);
}
for(int i=0; i<110; i++)
{
dp[1][i]=(e+s)*i;
}
for(int i=2;i<=n;i++)
{
for(int j=a[i];j<110;j++)//本月至少要a[i]个人
{
mn=inf;
for(int k=a[i-1];k<110;k++)//上月必须要到a[i-1]个人才符合
{
if(k<=j)
mn=min(mn,dp[i-1][k]+k*s+(j-k)*(s+e));//人增多,多雇佣
else
mn=min(mn,dp[i-1][k]+j*s+(k-j)*f);//人减少,解雇
}
dp[i][j]=mn;
}
}
mn=inf;
for(int i=a[n];i<110;i++)
{
mn=min(mn,dp[n][i]);
}
printf("%d\n",mn); }
return 0;
}

hdu1158 Employment Planning 2016-09-11 15:14 33人阅读 评论(0) 收藏的更多相关文章

  1. Toad for MySQL 7.3 Freeware异常 2017-01-09 15:14 115人阅读 评论(0) 收藏

    打开Toad出现如下异常信息: 解决办法: 重装.NET Framework4.0

  2. TextView之一:子类的常用属性 分类: H1_ANDROID 2013-10-30 15:14 770人阅读 评论(0) 收藏

    TextView常见的子类包括EditText,Button,CheckBox, RadioButton等. 1.EditText EditText继承自TextView,因此TextView所有属性 ...

  3. PAT甲 1041. Be Unique (20) 2016-09-09 23:14 33人阅读 评论(0) 收藏

    1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being uniqu ...

  4. Gold Coins 分类: POJ 2015-06-10 15:04 16人阅读 评论(0) 收藏

    Gold Coins Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 21767   Accepted: 13641 Desc ...

  5. Curling 2.0 分类: 搜索 2015-08-09 11:14 3人阅读 评论(0) 收藏

    Curling 2.0 Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14289 Accepted: 5962 Descript ...

  6. Oracle垃圾数据清理相关问题 分类: Oracle 2015-08-06 11:14 12人阅读 评论(0) 收藏

    垃圾数据清理,简单的说,就是删除不需要的那些数据,释放存储空间 最常用的就是delete命令.truncate命令,甚至是删除表空间重建,具体操作都很简单,不是本文的重点 下面,总结几个垃圾数据清理常 ...

  7. Hdu4632 Palindrome subsequence 2017-01-16 11:14 51人阅读 评论(0) 收藏

    Palindrome subsequence Problem Description In mathematics, a subsequence is a sequence that can be d ...

  8. Jsp Cookie的创建与读取 标签: cookiejsp 2016-11-17 15:14 61人阅读 评论(0)

    Cookie.jsp <%@ page language="Java" import="java.util.*" pageEncoding="u ...

  9. Velocity浅析及与Jsp、Freemarker对比 分类: B1_JAVA 2014-07-21 09:14 637人阅读 评论(0) 收藏

    转载自:http://www.cnblogs.com/petermsdn/archive/2011/05/06/2039178.html Velocity 是一个基于java 的模板引擎(templa ...

随机推荐

  1. 刚刚安装完nginx,服务启动,通过浏览器无法访问的问题

    查看Linux服务是否启动. ps -ef | grep nginx 解决办法:1,添加 80 段端口配置 firewall-cmd --zone=public --add-port=80/tcp - ...

  2. ArcGIS模型构建器案例学习笔记-字段处理模型集

    ArcGIS模型构建器案例学习笔记-字段处理模型集 联系方式:谢老师,135-4855-4328,xiexiaokui@qq.com 由四个子模型组成 子模型1:判断字段是否存在 方法:python工 ...

  3. Hive—简单窗口分析函数

    hive 窗口分析函数 : jdbc:hive2:> select * from t_access; +----------------+---------------------------- ...

  4. Top K算法

    应用场景: 搜索引擎会通过日志文件把用户每次检索使用的所有检索串都记录下来,每个查询串的长度为1-255字节.        假设目前有一千万个记录(这些查询串的重复度比较高,虽然总数是1千万,但如果 ...

  5. Sql求和异常——对象不能从 DBNull 转换为其他类型

    做项目遇到一个以前没遇到的问题,就是要计算一个用户消费总额, 关键代码如下: string sql = "select sum(Tmoney) from [order] where uid= ...

  6. 使用一般处理程序(IHttpHandler)制作图片水印

    做网站的时候经常需要将图片加上网站名称的水印.这样做可以使别人转载图片的时候出现图片出处 ,利于网站宣传.但是如果利用ps来一个一个加水印工作量非常浩大,而且修改了之后就没法还原.这 篇教程教大家利用 ...

  7. 【校招面试 之 C/C++】第16题 C++ new和delete的实现原理

    1.new new操作针对数据类型的处理,分为两种情况: (1)简单数据类型(包括基本数据类型和不需要构造函数的类型) 代码实例: int* p = new int; 汇编码如下: int* p = ...

  8. 将tomcat做成服务

    ①修改startup.bat 在第一行前加入如下内容: SETJAVA_HOME=D:\ProgramFiles\tool\Java\jdk1.6 SETCATALINA_HOME=D:\Progra ...

  9. 搜索旋转排序数组 II

    跟进“搜索旋转排序数组”,假如有重复元素又将如何? 一句话思路:不能二分,因为复杂度是n eg全是0,找一个1 class Solution { public boolean search(int[] ...

  10. layui学习<一>

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name ...