http://poj.org/problem?id=2393

Yogurt factory
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 7341   Accepted: 3757

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 Input

4 5
88 200
89 400
97 300
91 500

Sample Output

126900

Hint

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. 

Source

 
 
 
分析:

简单DP~求最少的花费~

题目是说你每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶需要花费S元,让你求出所有周的需求量上交的最少花费。

将S转换到花费中~

AC代码:

 #include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int maxn=;
int n,s;
int y[maxn],c[maxn];
int main()
{
while(scanf("%d%d",&n,&s)!=EOF)
{
for(int i=;i<n;i++)
scanf("%d%d",&c[i],&y[i]);
long long ans=;
for(int i=;i<n;i++)
c[i]=min(c[i-]+s,c[i]);
for(int i=;i<n;i++)
ans+=c[i]*y[i];
printf("%lld\n",ans);
}
return ;
}

AC代码:

 #include<cstdio>

 using namespace std;
int a[],b[]; int main() {
int n,s;
while(~scanf("%d %d",&n,&s)) {
for(int i = ;i < n;i++) {
scanf("%d %d",&a[i],&b[i]);
} __int64 res = a[] * b[];
for(int i = ;i < n;i++) {
int mi = ,pos = -;
for(int j = ;j < i;j++) {
if(mi > s * (i - j) && (a[i] - a[j] > s * (i - j)) ) {
mi = s * (i - j);
pos = j;
}
}
if(pos != -)
res += a[pos] * b[i] + mi * b[i];
else
res += a[i] * b[i];
}
printf("%I64d\n",res);
}
return ;
}

poj 2393 Yogurt factory的更多相关文章

  1. POJ 2393 Yogurt factory 贪心

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

  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 2373 Yogurt factory

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

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

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

  7. Yogurt factory(POJ 2393 贪心 or DP)

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8205   Accepted: 4197 De ...

  8. BZOJ1680: [Usaco2005 Mar]Yogurt factory

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

  9. 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂

    1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 119  Solved:  ...

随机推荐

  1. JS里面的两种运动函数

    最新学了一个新的运动函数,与最初学习的有所不同,第一个运动是根据运动速度完成运动 ,第二个则是根据运动的时间来完成运动,而且把之前的函数都进行了一些兼容处理,在这里列出了看一下: 第一种animate ...

  2. PHP实现快速排序、插入排序、选择排序

    1.快速排序 快速排序(Quicksort)是对冒泡排序的一种改进.由C. A. R. Hoare在1962年提出.它的基本思想是:通过一趟排序将要排序的数据分割成独立的两部分,其中一部分的所有数据都 ...

  3. SqlServer操作大全

    一.基础1.说明:创建数据库CREATE DATABASE database-name2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备份数 ...

  4. java调用url接口

    很多简单的接口就是直接一个URl的形式, 怎么调用? HttpClient httpclient=null; PostMethod post=null; try{ httpclient = new H ...

  5. 常见的HTTP Headers

    协议就是交互双方协商好要遵守的规范,打个不恰当的比方,就好像交谈双方约定要使用的同一种语言.如果我讲英文,你讲中文,大家都相互听不懂,交流那就得嗝屁了. HTTP协议就是需要交互的客户端(通常是浏览器 ...

  6. HTML 5 拖放(Drag 和drop)

    浏览器支持 Internet Explorer 9.Firefox.Opera 12.Chrome 以及 Safari 5. 1.把标签 draggable 属性设置为 true. 2.向标签添加on ...

  7. HTML基础篇之HTML基本结构

    课堂知识总结 第一接触和学习HTML知识在学习过程中对所属的标签的自己认为的理解和解释. HTML元素:文档里面的标签和内容. 比如:<h1>大家好</h1>  左边的是开始标 ...

  8. PHPExcel中文开发手册翻译版(1)

    请注意这个是粗翻译版,仅供参考,不是精校版 精校版后面才会更新 英文原版在线文档 https://github.com/PHPOffice/PHPExcel/wiki/User%20Documenta ...

  9. cocos2dx的android版FileUtils的坑

    cocos2dx3.13,FileUtils-android.cpp中可以看到: FileUtils::Status FileUtilsAndroid::getContents(const std:: ...

  10. Java Basic - Generics

    什么是类型擦除? 类型擦除指的是通过类型参数合并,将泛型类型实例关联到同一份字节码上.编译器只为泛型类型生成一份字节码,并将其实例关联到这份字节码上.类型擦除的关键在于从泛型类型中清除类型参数的相关信 ...