题目传送门

Employment Planning

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 6242    Accepted Submission(s): 2710

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
 
Source
 
Recommend
Ignatius   |   We have carefully selected several similar problems for you:  1227 1074 1080 1024 1078 
题意:给出n个月,雇佣价钱,工资和辞退价钱;然后给出每个月所需的人数,
        求最小花费
题解:定义dp[i][j]为以i月份结尾,j个人数的花费最小值
 则dp[i][j]=min{dp[i-1][k]+cost[i][j]};
   其中当k<=j时,cost[i][j]=j*salary+(j-k)*hire;
          k>j时,cost[i][j]=j*salary+(k-j)*fire;
边界就是 for(int i=people[1];i<=maxn;i++)
        dp[1][i]=i*salary+i*hire;
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define mod 1000000007
#define INF 0x3f3f3f3f
int n;
int people[];
int dp[][];
int hire,salary,fire;
int main()
{
while(cin>>n)
{
if(n==) break;
cin>>hire>>salary>>fire;
int maxn=;
for(int i=;i<=n;i++)
{
cin>>people[i];
maxn=max(maxn,people[i]);
}
memset(dp,INF,sizeof(dp));
for(int i=people[];i<=maxn;i++)
dp[][i]=i*salary+i*hire;
for(int i=;i<=n;i++)
{
for(int j=people[i];j<=maxn;j++)
{
for(int k=people[i-];k<=maxn;k++)
{
if(k<=j)
dp[i][j]=min(dp[i][j],dp[i-][k]+j*salary+(j-k)*hire);
else
dp[i][j]=min(dp[i][j],dp[i-][k]+j*salary+(k-j)*fire);
}
}
}
int minn=INF;
for(int i=people[n];i<=maxn;i++)
{
minn=min(minn,dp[n][i]);
}
cout<<minn<<endl;
}
return ;
}

hdu1158 Employment Planning(dp)的更多相关文章

  1. hdu 1158 Employment Planning(DP)

    题意: 有一个工程需要N个月才能完成.(n<=12) 给出雇佣一个工人的费用.每个工人每个月的工资.解雇一个工人的费用. 然后给出N个月所需的最少工人人数. 问完成这个项目最少需要花多少钱. 思 ...

  2. HDU 1158 Employment Planning (DP)

    题目链接 题意 : n个月,每个月都至少需要mon[i]个人来工作,然后每次雇佣工人需要给一部分钱,每个人每个月还要给工资,如果解雇人还需要给一笔钱,所以问你主管应该怎么雇佣或解雇工人才能使总花销最小 ...

  3. LightOJ 1033 Generating Palindromes(dp)

    LightOJ 1033  Generating Palindromes(dp) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid= ...

  4. lightOJ 1047 Neighbor House (DP)

    lightOJ 1047   Neighbor House (DP) 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87730# ...

  5. UVA11125 - Arrange Some Marbles(dp)

    UVA11125 - Arrange Some Marbles(dp) option=com_onlinejudge&Itemid=8&category=24&page=sho ...

  6. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  7. 初探动态规划(DP)

    学习qzz的命名,来写一篇关于动态规划(dp)的入门博客. 动态规划应该算是一个入门oier的坑,动态规划的抽象即神奇之处,让很多萌新 萌比. 写这篇博客的目标,就是想要用一些容易理解的方式,讲解入门 ...

  8. Tour(dp)

    Tour(dp) 给定平面上n(n<=1000)个点的坐标(按照x递增的顺序),各点x坐标不同,且均为正整数.请设计一条路线,从最左边的点出发,走到最右边的点后再返回,要求除了最左点和最右点之外 ...

  9. 2017百度之星资格赛 1003:度度熊与邪恶大魔王(DP)

    .navbar-nav > li.active > a { background-image: none; background-color: #058; } .navbar-invers ...

随机推荐

  1. java Activiti6.0 后台 框架 spring5 SSM 工作流引擎 审批流程

    1.模型管理 :web在线流程设计器.预览流程xml.导出xml.部署流程 2.流程管理 :导入导出流程资源文件.查看流程图.根据流程实例反射出流程模型.激活挂起 3.运行中流程:查看流程信息.当前任 ...

  2. java随机数Math.random()

    double random=Math.random();//返回[0,1)随机数 (int)(Math.random()*6)//返回0-5:随机数 (int)(Math.random()*6+1)/ ...

  3. elasticsearch 基础 —— Query String

    使用查询解析器来解析其内容的查询.下面是一个例子: GET /_search { "query": { "query_string" : { "def ...

  4. Django 高级配置

    目录 Django 信号 信号系统三要素: 信号的分类: Django 内置信号: 具体 Django 信号内容 定义信号 发送信号 接收信号 信号接收器 防止重复信号 Django 内置信号操作步骤 ...

  5. Linux 进程通信之:内存共享(Shared Memory)(转,好文章)

    https://blog.csdn.net/afei__/article/details/84188548

  6. [BZOJ3653]谈笑风生 主席树

    题面 这道题应该比较裸吧. \(a\),\(b\)都是\(c\)的祖先. 那么第一种情况是\(b\)是\(a\)的祖先,那么方案数就是\(\min\{dep[a]-1,k\}\cdot (num[a] ...

  7. PhpStorm中如何使用database工具

    环境:ubuntu18.4 mysql5.7 一. 打开database 1.选择View—>Tool Windows—>Database单击打开. 2.新增数据连接 选择 “+”—> ...

  8. maven仓库mirrors

    <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> & ...

  9. spark数据分析导论

    1.spark的定义 spark是一个用来实现快速而通用的集群计算平台,高效的支持更多计算模式,包括交互式查询和流处理. 主要特点就是能够在内存中进行计算,即使在磁盘上进行计算依然比mapreduce ...

  10. Win7 ODBC驱动 Excel (转)

    “控制面板-管理工具-数据源(ODBC)”,打开“ODBC数据源管理器”窗口,然后“添加”,打开“创建新数据源”的窗口,最后选择Microsoft Access Driver(*.mdb)选项,往后等 ...