Employment Planning

Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u

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
#include<stdio.h>
#include<string.h> const int INF=99999999; int dp[15][10010];
int people[15]; int main()
{
int n;
int h,s,f;
while(~scanf("%d",&n),n)
{
scanf("%d%d%d",&h,&s,&f);
int max_people=0;
int i,j,k;
for(i=1; i<=n; i++)
{
scanf("%d",&people[i]);
if(max_people<people[i])
max_people=people[i];
}
for(i=people[1]; i<=max_people; i++) //初始化第一个月
dp[1][i]=i*s+i*h;
int min;
for(i=2; i<=n; i++)
{
for(j=people[i]; j<=max_people; j++)
{
min=INF; //有了这个前面就不需要用O(n^2)初始化dp了。
for(k=people[i-1]; k<=max_people; k++)
if(min>dp[i-1][k]+(j>=k?(j*s+(j-k)*h):(j*s+(k-j)*f)))
min=dp[i-1][k]+(j>=k?(j*s+(j-k)*h):(j*s+(k-j)*f));
dp[i][j]=min;
}
}
min=INF;
for(i=people[n]; i<=max_people; i++)
if(min>dp[n][i])
min=dp[n][i];
printf("%d\n",min);
}
return 0;
}

hdu 1158 dp Employment Planning的更多相关文章

  1. hdu 1158 dp

    /* 题目大意:给n个月工作需要的人数,雇佣一个需要花hire 每个月的薪水是salary,解雇一个需要fire 求完成所有工作的最小费用 dp(i,j)表示第i个月雇佣j员工的最小费用 */ #in ...

  2. HDU 1158 Employment Planning (DP)

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

  3. HDU 1158(非常好的锻炼DP思维的题目,非常经典)

    题目链接: acm.hdu.edu.cn/showproblem.php?pid=1158 Employment Planning Time Limit: 2000/1000 MS (Java/Oth ...

  4. Employment Planning DP

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  5. hdu1158 Employment Planning(dp)

    题目传送门 Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  6. HDU1158:Employment Planning(暴力DP)

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. Employment Planning[HDU1158]

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

  8. hdu1158 Employment Planning 2016-09-11 15:14 33人阅读 评论(0) 收藏

    Employment Planning Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  9. Employment Planning

    Employment Planning 有n个月,每个月有一个最小需要的工人数量\(a_i\),雇佣一个工人的费用为\(h\),开除一个工人的费用为\(f\),薪水为\(s\),询问满足这n个月正常工 ...

随机推荐

  1. MongoDB - MongoDB CRUD Operations, Query Documents, Iterate a Cursor in the mongo Shell

    The db.collection.find() method returns a cursor. To access the documents, you need to iterate the c ...

  2. 2016-2017-2 20155117实验二《Java面向对象程序设计》实验报告

    实验内容 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O.L.I.D原则 了解设计模式 实验要求 1.参考Intellj IDEA 简易教程 提交 ...

  3. python学习笔记(十二)之函数

    牛刀小试: 定义一个无参函数 >>> def myFirstFunc(): ... print("Hello python") ... print("h ...

  4. UVA - 10494 If We Were a Child Again

    用java写的大数基本操作,java要求的格式比较严谨. import java.util.*; import java.math.*; public class Main { public stat ...

  5. 2017ACM暑期多校联合训练 - Team 7 1002 HDU 6121 Build a tree (深搜+思维)

    题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n− ...

  6. 爬虫实战--使用Selenium模拟浏览器抓取淘宝商品美食信息

    from selenium import webdriver from selenium.webdriver.common.by import By from selenium.common.exce ...

  7. CMDB概述(二)

    运维自动化路线: cmdb的开发需要包含三部分功能: ·采集硬件数据  ·API ·页面管理 执行流程:服务器的客户端采集硬件数据,然后将硬件信息发送到API,API负责将获取到的数据保存到数据库中, ...

  8. python 输出 a+b

    AC代码: 单组输入: s=input().split() print(int(s[0])+int(s[1]))

  9. [HTML]增加input标签的multiple属性上传的文件数

    .发现问题 <input type="file" name="myfile[]" multiple="multiple"/> 最 ...

  10. C# 解决窗体闪烁

    C# 解决窗体闪烁 在Windows窗体上造成“闪烁”的窗体上有很多控制.造成这种闪烁的原因有两个: 1.当控件需要被绘制时,Windows发送一个控件两个消息.第一个(WM_ERASEBKGND)导 ...