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. fiddler无法抓取chrome解决方法

    前端开发中,不可避免的要和服务器端进行联调,少了fiddler这个利器可不行. 由于无线开发需要配置UA,我使用chrome进行访问,但是今儿一早过来,发现fiddler无法抓取chrome的请求了. ...

  2. General error 2006 MySQL server has gone away

    写入配置文件的办法: max_allowed_packet = 16M //但是这种有时候不支持,1024*1024*16这种有的也不支持 max_allowed_packet = 16777216 ...

  3. RedisTemplate Redis 操作

    stringRedisTemplate.opsForValue().set("test", "100",60*10,TimeUnit.SECONDS);//向r ...

  4. TOMCAT下面发布项目的4种方式

    摘要 TOMCAT下面发布项目的4种方式,可用于在平时资料查询. 第一种方法: 将web项目文件件拷贝到webapps 目录中:或者直接通过Eclipse发布到Tomcat上. 第二种方法: 在tom ...

  5. Appium学习路-安装篇

    比较好的文章:http://www.15yan.com/story/4GbuTwXQKDU/ 官网资料:http://appium.io/slate/cn/v1.2.0/?python#appium ...

  6. Python format 格式化函数。

    Python format 格式化函数  Python 字符串 Python2.6 开始,新增了一种格式化字符串的函数 str.format(),它增强了字符串格式化的功能. 基本语法是通过 {} 和 ...

  7. Python sum() 函数

    Python sum() 函数  Python 内置函数 描述 sum() 方法对系列进行求和计算. 语法 以下是 sum() 方法的语法: sum(iterable[, start]) 参数 ite ...

  8. tf.cast()

    一.函数 tf.cast() cast( x, dtype, name=None ) 将x的数据格式转化成dtype.例如,原来x的数据格式是bool, 那么将其转化成float以后,就能够将其转化成 ...

  9. 快速排序C++实现

    #include<iostream> using namespace std;class quicksort{ public: int quicks(int *a,int low,int ...

  10. HTML 视频(Videos)

    前端video做起来很简单,但是还是需要做一些记录,不然下次再做相关的业务仍得费时间找. 参考地址: http://www.jq22.com/jquery-info404 http://www.run ...