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. 设计模式(2)工厂方法模式(Factory Method)

    设计模式(0)简单工厂模式 设计模式(1)单例模式(Singleton) 源码地址 0 工厂方法模式简介 0.0 工厂方法模式定义 工厂方法模式是在简单工厂模式基础上,为解决更复杂的对象创建问题而衍生 ...

  2. loadrunner 手工参数拼接与l oadrunner的url编码

    Acction() { //演示需要的一些变量,提前声明 char *name = "yezi_zh"; "; char *work = "engin" ...

  3. 基于Dubbo的分布式事务框架(LCN)

    原文地址:http://原文地址:https://github.com/1991wangliang/transaction 基于Dubbo的分布式事务框架(LCN) 该框架依赖Redis/dubbo/ ...

  4. php 多维数组简化(递归)

    <?php $a=[ 'a'=>['d'=>['aa'=>1,'bb'=>2,'cc'=>3]], 'b'=>['f'=>['dd'=>4,'ee ...

  5. Kafka 源代码分析之MessageSet

    这里分析MessageSet类 MessageSet是一个抽象类,定义了一条log的一些接口和常量,FileMessageSet就是MessageSet类的实现类.一条日志中存储的log完整格式如下 ...

  6. 怎么利用composer创建laravel项目

    前提:已经安装了composer的电脑 创建laravel项目: 第一步: 找到你要创建文件的地方 然后打开doc,输入:composer create_project laravel/laravel ...

  7. 游戏UI框架设计(7): 资源国际化技术

    游戏UI框架设计(7) --资源国际化技术 说起"资源国际化"技术,个人认为可以追述到微软Window2000 PC操作系统的发布,在这之前windows98操作系统的开发都是先由 ...

  8. 使用docker-compose搭建AspNetCore开发环境

    1 使用docker-compose搭建开发环境 我们的目标很简单:使用docker-compose把若干个docker容器组合起来就成了. 首先使用Nginx代理所有的Web程序,这样只需要在主机上 ...

  9. gulp 入门指南

    gulp 是基于 node 实现 Web 前端自动化开发的工具,利用它能够极大的提高开发效率. 在 Web 前端开发工作中有很多"重复工作",比如压缩CSS/JS文件.而这些工作都 ...

  10. Jemeter基础

    jemeter主要组件: a.测试计划(Test Plan) 是使用JMeter进行测试的起点,它是其它JMeter测试元件的容器. b.线程组(Thread Group) 代表一定数量的并发用户,它 ...