2393:Yogurt factory

总时间限制: 
1000ms

内存限制: 
65536kB
描述
The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the next N (1 <= N <= 10,000) weeks, the price of milk and labor will fluctuate weekly such that it will cost the company C_i (1 <= C_i <= 5,000) cents to produce one unit of yogurt in week i. Yucky's factory, being well-designed, can produce arbitrarily many units of yogurt each week.

Yucky Yogurt owns a warehouse that can store unused yogurt at a constant fee of S (1 <= S <= 100) cents per unit of yogurt per week. Fortuitously, yogurt does not spoil. Yucky Yogurt's warehouse is enormous, so it can hold arbitrarily many units of yogurt.

Yucky wants to find a way to make weekly deliveries of Y_i (0 <= Y_i <= 10,000) units of yogurt to its clientele (Y_i is the delivery quantity in week i). Help Yucky minimize its costs over the entire N-week period. Yogurt produced in week i, as well as any yogurt already in storage, can be used to meet Yucky's demand for that week.
输入
* Line 1: Two space-separated integers, N and S.

* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.
输出
* Line 1: Line 1 contains a single integer: the minimum total cost to satisfy the yogurt schedule. Note that the total might be too large for a 32-bit integer.
样例输入
4 5
88 200
89 400
97 300
91 500
样例输出
126900
提示
OUTPUT DETAILS:
In week 1, produce 200 units of yogurt and deliver all of it. In week 2, produce 700 units: deliver 400 units while storing 300 units. In week 3, deliver the 300 units that were stored. In week 4, produce and deliver 500 units.
【题目大意】 

有一个制作酸奶的工厂,需要在接下来的N(1<=N<=10000)周里
生产酸奶,第i周的成本为Ci(1<=Ci<=5000),工厂有一个无限大的仓库可
以存储生产好了的酸奶,并且这些酸奶不会过期,可以一直存储,但是存
储每单位酸奶每周要花费S(1<=S<=100)。计算:要满足条件:工厂第i周必
须送出Yi(1<=Yi<=10000)单位的酸奶(可以从仓库中送出,也可以本周生产),
最小花费是多少?

【样例说明】:第一周生产200单位酸奶并且全部送出;第二周,生产700单位:送出400,存储300; 第三周,送出第二周存储的300单位; 第四周,生产500单位并全部送出。

【题目分析】 第i周的酸奶可以是任意小于i的周生产的。于是如果第i周的酸奶在第j(i>j)周生产,相当于这酸奶在第j周生产,并且花费是第i周的成本加上(i-j)周的储存费用。

第i周的最小花费是可以由第i-1周的最小花费推出的:mincost(i) = min( mincost(i-1)+s,Ci );而第一周的最小成本就是C1,因为第一周的酸奶只能第一周生产。

于是从第一周开始可以逐步推出所有周的最小花费:

  

1 for( int i=1; i<=N-1; i++ ) {
2 week[i].C = min( week[i-1].C+S,week[i].C );
3 //i推i+1,到N-1时就已经推出N了 N单独处理就行了
4 }

关于数据范围:最坏的情况是,有10000周,每周都需要送出10000单位酸奶,
并且每周的成本都是5000.在这种情况下,共需要10000*5000*10000=5e+11的花费。
所以使用long long 就可以了。

【代码】

 1 #include <iostream>
2 #include <algorithm>
3 using namespace std;
4
5 const int maxn = 10010;
6
7 struct _week
8 {
9 int C;
10 int Y;
11 };
12 _week week[maxn];
13 int N,S;
14
15 int main()
16 {
17 cin >> N >> S;
18 long long totalcost = 0;
19 for( int i=1; i<=N; i++ ) {
20 cin >> week[i].C >> week[i].Y;
21 }
22
23 //推出2到N-1周的最小花费同时计算总费用
24 for( int i=1; i<=N-1; i++ ) {
25 totalcost += week[i].C * week[i].Y;
26 week[i+1].C = min( week[i].C+S,week[i+1].C );
27 }
28
29 //总费用加上最后一周(第N周)的花费
30 totalcost += week[N].C * week[N].Y;
31 cout << totalcost << endl;
32 return 0;
33 }

百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】的更多相关文章

  1. POJ2393 Yogurt factory 【贪心】

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6821   Accepted: 3488 De ...

  2. poj2393 Yogurt factory(贪心,思考)

    https://vjudge.net/problem/POJ-2393 因为仓储费是不变的. 对于每一周,要么用当周生产的,要么接着上一周使用的价格(不一定是输入的)加上固定的仓储费用. 应该算是用到 ...

  3. POJ-2393 Yogurt factory 贪心问题

    题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...

  4. poj-2393 Yogurt factory (贪心)

    http://poj.org/problem?id=2393 奶牛们有一个工厂用来生产奶酪,接下来的N周时间里,在第i周生产1 单元的奶酪需要花费ci,同时它们也有一个储存室,奶酪放在那永远不会坏,并 ...

  5. poj2393 Yogurt factory

    思路: 贪心. 实现: #include <iostream> #include <cstdio> #include <algorithm> using names ...

  6. POJ 2393 Yogurt factory 贪心

    Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...

  7. BZOJ 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 贪心 + 问题转化

    Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...

  8. poj 2393 Yogurt factory

    http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  9. BZOJ1680: [Usaco2005 Mar]Yogurt factory

    1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 106  Solved: 74[Su ...

随机推荐

  1. Nginx超详细常用功能演示,够用啦~~~

    前言 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服 ...

  2. API网关才是大势所趋?SpringCloud Gateway保姆级入门教程

    什么是微服务网关 SpringCloud Gateway是Spring全家桶中一个比较新的项目,Spring社区是这么介绍它的: 该项目借助Spring WebFlux的能力,打造了一个API网关.旨 ...

  3. 重新整理 .net core 实践篇————配置应用[一]

    前言 本来想整理到<<重新整理.net core 计1400篇>>里面去,但是后来一想,整理 .net core 实践篇 是偏于实践,故而分开. 因为是重新整理,那么就从配置开 ...

  4. [设计模式] 设计模式课程(十二)-- 门面模式(Facade)

    概述 也称外观模式 按目的属于结构型模式,按封装属于接口隔离模式 在组件构建过程中,某些接口之间的依赖常常会带来很多问题.甚至根本无法实现.采用添加一层间接(稳定)接口,来隔离本来互相紧密关联的接口 ...

  5. Linux 操作系统(四)用户组管理&进程管理&任务调度

    以下实例均在Centos7下验证 Centos7 查看命令帮助 man xxx 用户组管理 useradd useradd user1 password user1 cat /etc/passwd # ...

  6. openstack宿主机故障,虚拟实例恢复

    前言: 因为机房服务器运行不稳定的原因导致计算节点挂掉,然后上面的Centos7虚拟机在迁移之后开机报错.这个解决方法同样适用于其它操作系统的虚拟机.基于镜像创建的虚拟机实例. I/O error, ...

  7. 2019年又迎来Hi1620,鲲鹏920则是Hi1620系列的正式品牌和型号

    据记者了解,2013年华为就发布了Hi1610,2014年的Hi1612是ARM64位CPU,2016年的Hi1616是首颗支持多路的ARM处理器,2019年又迎来Hi1620,鲲鹏920则是Hi16 ...

  8. Windows10查看电脑的USB接口是2.0还是3.0

    Windows10查看电脑的USB接口是2.0还是3.0原创小晓酱手记 最后发布于2019-08-22 16:09:48 阅读数 3662 收藏展开 同事要拷贝资料给我,问我电脑的USB接口是2.0还 ...

  9. S5 Linux信息显示与搜索文件命令

    5.1-5 uname.hostname.dmesg.stat.du 5.6 date:显示与设置系统时间 5.7 echo:显示一行文本 5.8-12 watch.which.whereis.loc ...

  10. fprintf函数

    描述 C 库函数 int fprintf(FILE *stream, const char *format, ...) 发送格式化输出到流 stream 中. 声明 下面是 fprintf() 函数的 ...