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.

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.

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.

Sample

Sample Input

Sample Output

题意:

  有一个奶酪工厂,给出这个工厂每天加工每个奶酪需要的价格,以及每天的需求量,另外,奶酪也可以存放在仓库里,给出每个奶酪存放一天需要的价格,问,这些生产任务全部完成,最少的花费是多少?

思路:

  第一天的奶酪只能当天生产,这是无法贪心选取的,所以第一天只能取当天的值,第二天就可以选择第二天和第一天生产哪个更优了,同理第三天选择第一天第二天和第三天哪一个更优。第二天的价格是第二天的价格的和第一天生产的价格加上存储费用的较小的值。这样,每天都维护一个最小值即可,维护的时候只要和前一周比较就行了。比如第三周和第二周比较,因为第二周更新的时候取值就是第一周和第二周的最小值,第三周和第二周比较就是第三周与前两周的最小值比较,一次只需要和前一周比较。

代码:

#include<stdio.h>
#include<stack>
#include<algorithm>
#include<queue>
#include<iostream>
#include<string.h>
#include<string>
using namespace std;
int main()
{
int n,m;
int cost[],cnt[];
scanf("%d%d",&n,&m);
for(int i=; i<n; i++)
scanf("%d%d",cost+i,cnt+i);
long long ans=;
for(int i=; i<n; i++)
cost[i]=min(cost[i-]+m,cost[i]);
for(int i=; i<n; i++)
ans+=cost[i]*cnt[i];
printf("%lld\n",ans);
return ;
}

  

POJ 2393 Yogurt factory 贪心的更多相关文章

  1. poj 2393 Yogurt factory

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

  2. POJ 2393 Yogurt factory【贪心】

    POJ 2393 题意: 每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶 ...

  3. 贪心问题 POJ 2393 Yogurt factory

    题目:http://poj.org/problem?id=2393 题意:N周,每周生成牛奶(任意!),每周成本为c_i(1~5000),每周出货 y_i:出货可以使用该周生产的,也可以用之前的储存的 ...

  4. poj 2393 Yogurt factory(dp+贪心)

    奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S.求总体最低成本. 贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的.于是该周单位成本 ...

  5. poj_2393 Yogurt factory 贪心

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16669   Accepted: 8176 D ...

  6. poj-2393 Yogurt factory (贪心)

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

  7. POJ 2373 Yogurt factory

    简单DP. 这周所用的实际花费是上一周的花费+S与这周费用的较小值. #include<cstdio> #include<cstring> #include<cmath& ...

  8. POJ-2393 Yogurt factory 贪心问题

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

  9. 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】

    2393:Yogurt factory 总时间限制:  1000ms 内存限制:  65536kB 描述 The cows have purchased a yogurt factory that m ...

随机推荐

  1. 安装nginx+lua开发环境

    一.安装nginx及搭建本地测试环境 1.创建安装目录:    /data/nginx2.安装make:        yum-y install gcc automake autoconf libt ...

  2. Linux基础命令之总结一

    [root@ping ~]# tree -L 1 /   #使用tree 命令查看根目录下的一层的目录结构 ls - list directory contents[root@ping ~]# ls ...

  3. c#中foreach的一种用法

    以下定义的MyClass类中的addnum方法使用了一个数组型参数b: public class MyClass { ; public void addnum(ref int sum, params ...

  4. EventBus In eShop -- 解析微软微服务架构Demo(四)

    引言 大家好像对分析源码厌倦了,说实在我也会厌倦,不过不看是无法分析其后面的东西,从易到难是一个必要的过程. 今天说下EventBus,前几天园里的大神已经把其解刨,我今天就借着大神的肩膀,分析下在e ...

  5. 【Android Developers Training】 35. 序言:分享文件

    注:本文翻译自Google官方的Android Developers Training文档,译者技术一般,由于喜爱安卓而产生了翻译的念头,纯属个人兴趣爱好. 原文链接:http://developer ...

  6. 在ASP.NET CORE 2.0使用SignalR技术

    一.前言 上次讲SignalR还是在<在ASP.NET Core下使用SignalR技术>文章中提到,ASP.NET Core 1.x.x 版本发布中并没有包含SignalR技术和开发计划 ...

  7. web前端2017.6.10

    表单元素:用于客户端和服务端进行信息交互的通道 <form></form>:所有的表单元素都应该放在里面 文本输入框:<input type="text&quo ...

  8. Linux离线安装Ruby详解

    很多时候我们会发现,真实的生成环境很多都没有外网,只有内网环境,这个时候我们又需要安装Ruby,则不能提供yum命令进行在线安装了,这个时候我们就需要下载安装包进行离线安装.本文主要简单介绍如果离线安 ...

  9. Swift3 GCD队列优先级说明

    从ios8开始,苹果引入了一个新的概念 QoS(quality of service),用于指定GCD队列的优先级. swift3之前:只有4个优先级 high > default > l ...

  10. JavaWeb 后端 <六> 之 EL & JSTL 学习笔记

    一.EL表达式(特别重要)