poj 2393 Yogurt factory
http://poj.org/problem?id=2393
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 7341 | Accepted: 3757 |
Description
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
* Lines 2..N+1: Line i+1 contains two space-separated integers: C_i and Y_i.
Output
Sample Input
4 5
88 200
89 400
97 300
91 500
Sample Output
126900
Hint
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的更多相关文章
- POJ 2393 Yogurt factory 贪心
Description The cows have purchased a yogurt factory that makes world-famous Yucky Yogurt. Over the ...
- POJ 2393 Yogurt factory【贪心】
POJ 2393 题意: 每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶 ...
- 贪心问题 POJ 2393 Yogurt factory
题目:http://poj.org/problem?id=2393 题意:N周,每周生成牛奶(任意!),每周成本为c_i(1~5000),每周出货 y_i:出货可以使用该周生产的,也可以用之前的储存的 ...
- poj 2393 Yogurt factory(dp+贪心)
奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S.求总体最低成本. 贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的.于是该周单位成本 ...
- POJ 2373 Yogurt factory
简单DP. 这周所用的实际花费是上一周的花费+S与这周费用的较小值. #include<cstdio> #include<cstring> #include<cmath& ...
- 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】
2393:Yogurt factory 总时间限制: 1000ms 内存限制: 65536kB 描述 The cows have purchased a yogurt factory that m ...
- Yogurt factory(POJ 2393 贪心 or DP)
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8205 Accepted: 4197 De ...
- BZOJ1680: [Usaco2005 Mar]Yogurt factory
1680: [Usaco2005 Mar]Yogurt factory Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 106 Solved: 74[Su ...
- 1740: [Usaco2005 mar]Yogurt factory 奶酪工厂
1740: [Usaco2005 mar]Yogurt factory 奶酪工厂 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 119 Solved: ...
随机推荐
- POJ 2559 Largest Rectangle in a Histogram ——笛卡尔树
[题目分析] 本来是单调栈的题目,用笛卡尔树可以快速的水过去. 把每一个矩阵看成一个二元组(出现的顺序,高度). 然后建造笛卡尔树. 神奇的发现,每一个节点的高度*该子树的大小,就是这一块最大的子矩阵 ...
- 读写注册表 registrykey 创建删除
namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { Initialize ...
- Only Link: Inheritance — private and protected inheritance in c++
reading note link: https://isocpp.org/wiki/faq/private-inheritance
- 【BZOJ1076】[SCOI2008]奖励关 状压DP+期望
[BZOJ1076][SCOI2008]奖励关 Description 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须 ...
- [转]netty对http协议解析原理
本文主要介绍netty对http协议解析原理,着重讲解keep-alive,gzip,truncked等机制,详细描述了netty如何实现对http解析的高性能. 1 http协议 1.1 描述 标示 ...
- 堆排序 Heapsort
Prime + Heap 简直神了 时间优化好多,顺便就把Heapsort给撸了一发 具体看图 Heapsort利用完全二叉树+大(小)顶锥的结构每次将锥定元素和锥最末尾的元素交换 同时大(小)顶锥元 ...
- 自定义一个字母Button
package com.example.administrator.yunstore.widget; import android.content.Context; import android.gr ...
- centos关闭防火墙
Centos7 关闭防火墙 CentOS 7.0默认使用的是firewall作为防火墙,使用iptables必须重新设置一下 1.直接关闭防火墙 systemctl stop firewalld.se ...
- 分组统计并计算每组数量sql
有 字段A 和B比如数据如下A B1 21 31 4 2 22 3 统计出的sql结果: A count 1 3 2 2 select a,count(b) from t gr ...
- c++聪聪看书(满分代码)
聪聪是一个善良可爱.睿智聪慧的好孩子.聪聪喜欢看书,这一天她在看一本书时看到了这样一个问题:给你一个正整数n,你要将它分成若干个自然数Ai的和的形式,并且使得这若干个自然数Ai的乘积尽量大,并输出最大 ...