1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
Time Limit: 5 Sec Memory Limit: 64 MB
Submit: 119 Solved: 100
Description
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.
牛们收购了一个奶酪工厂,接下来的N个星期里,牛奶价格和劳力价格不断起伏.第i周,生产一个单位奶酪需要Ci(1≤Ci≤5000)便士.工厂有一个货栈,保存一单位奶酪,每周需要S(1≤S≤100)便士,这个费用不会变化.货栈十分强大,可以存无限量的奶酪,而且保证它们不变质.工厂接到订单,在第i周需要交付Yi(0≤Yi≤104)单位的奶酪给委托人.第i周刚生产的奶酪,以及之前的存货,都可以作为产品交付.请帮牛们计算这段时间里完成任务的最小代价.
Input
* 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.
第1行输入两个整数N和S.接下来N行输入Ci和Yi.
Output
* 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.
输出最少的代价.注意,可能超过32位长整型.
Sample Input
4 5 88 200 89 400 97 300 91 500
Sample Output
126900 第1周生产200单位奶酪并全部交付;第2周生产700单位,交付400单位,有300单位;第3周交 付300单位存货.第4周生产并交付500单位.
HINT
Source
题解:很经典的递推题(根本算不上DP,甚至有几分贪心的味道在里面),第五次见到了,不多说了,直接上代码(HansBug:难以想象这种题居然上usaco金组= =)
1 /**************************************************************
2 Problem: 1740
3 User: HansBug
4 Language: Pascal
5 Result: Accepted
6 Time:28 ms
7 Memory:224 kb
8 ****************************************************************/
9
10 var
11 i,j,k,l,m,n:longint;
12 ans:int64;
13 function min(x,y:longint):longint;
14 begin
15 if x<y then min:=x else min:=y;
16 end;
17 begin
18 readln(n,m);
19 l:=maxlongint-m;
20 for i:=1 to n do
21 begin
22 readln(j,k);
23 l:=min(l+m,j);
24 ans:=ans+int64(l)*int64(k);
25 end;
26 writeln(ans);
27 readln;
28 end.
- UESTC 30 &&HDU 2544最短路【Floyd求解裸题】
- 我的第一个网页制作:Hello World!
- UESTC 1584 Washi与Sonochi的约定【树状数组裸题+排序】
- Hyperledger - 超级账本项目:简介,安装,案例
- 我的第三个网页制作:b、i、s、u、sub、sup标签的使用
- 【AlphaGo Zero 核心技术-深度强化学习教程代码实战04】Agent类和SARSA算法实现
- 我的第二个网页制作:p,hn,br标签的使用
- 超级账本项目:架构设计
- 我的第四个网页制作:列表标签
- “盛大游戏杯”第15届上海大学程序设计联赛夏季赛暨上海高校金马五校赛题解&&源码【A,水,B,水,C,水,D,快速幂,E,优先队列,F,暴力,G,贪心+排序,H,STL乱搞,I,尼姆博弈,J,差分dp
- 虎嗅主站盲打成功(已进后台)
- 我的第五个网页制作:pre、html转义、abbr标签的使用
- UVALive 3882 - And Then There Was One【约瑟夫问题】
- 超级账本项目:链码示例
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- PHP5.6读写excel表格文件操作示例
- php提取微信账单的有效信息
- PHP微信发送推送消息乱码的解决方法
- php实现微信企业付款到个人零钱功能
- 如何解决安装python3.6.1失败
- Python读取Excel数据并生成图表过程解析
- 解决keras模型保存h5文件提示无此目录问题
- 如何基于Python代码实现高精度免费OCR工具
- python怎么调用自己的函数
- Python datetime模块使用方法小结
- PHP hebrev()函数用法讲解
- PHP hex2bin()函数用法讲解
- PHP+jQuery实现即点即改功能示例
- PHP html_entity_decode()函数讲解
- PHP下载大文件失败并限制下载速度的实例代码