poj 2393 Yogurt Factory(贪心)

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.

题意:工厂每周生产奶酪的成本不同,每周生产奶酪达到指标后多余的可以储存,储存需要每周S的费用,问怎么生产成本最低,输出最低成本。

思路:DP;

具体:用每周的成本和前几周的最低的储存成本比较。

ac代码:

#include<stdio.h>
#include<string.h>
int min(int a,int b)
{
    if(a>b)
    return b;
    else
    return a;
}
int main()
{
    int a,b,i,j,n,x[100000],y[100000];
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        long long sum=0;
        for(i=1;i<=a;i++)
        scanf("%d%d",&x[i],&y[i]);
        for(i=2;i<=a;i++)
        x[i]=min(x[i],x[i-1]+b);
        for(i=1;i<=a;i++)
        sum+=x[i]*y[i];
        printf("%lld\n",sum);
    }
}

有什么问题可以评论提问。

poj 2393 Yogurt Factory(贪心)

时间: 2024-10-14 17:00:44

poj 2393 Yogurt Factory(贪心)的相关文章

poj 2393 Yogurt factory(贪心)

传送门 解题思路 对于第\(i\)周来说,最小的花费 \(sum=min(y[i]*(c[j]+s(i-j)))(1<=j<=i)\),所以\(sum=min(y[i]*(c[j]-s[j]+s[i])\),发现\(y[i]\)与\(s[i]\)均为定值,就是让最小化\(c[j]-s[j]\),然后就直接维护个最小值每次更新答案即可. 代码 #include<iostream> #include<cstdio> #include<cstring> #incl

poj 2393 Yogurt factory

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

POJ 2393 Yogurt factory【贪心】

POJ 2393 题意: 每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶需要花费S元,让你求出所有周的需求量上交的最少花费. 分析: 因为第 i 周的奶酪,可以在第 i 周生产,也可以在前几周生产,然后储存.通过把s转化为花费,跟原有花费去比较,取一个最小值,这样从头到尾,每一周都可以取得一个花费的最小值.贪心求解. #include<cstdio> #include

POJ 2393 Yogurt factory(简单贪心)

http://poj.org/problem?id=2393 题意:任务规定,一个酸奶制造厂,在n个星期内,分别要向外提供y[i]unit的酸奶.已知这个制造厂第i周制造每unit酸奶的费用为c[i],储存室储存每1unit酸奶1星期的费用为s.问要完成这个任务的最小费用是多少. . . . . . . . . . . . . . 思路:简单贪心.维护一个目前最优的代价minc = min(c, minc + s),然后求和. #include <iostream> using namespa

贪心问题 POJ 2393 Yogurt factory

题目:http://poj.org/problem?id=2393 题意:N周,每周生成牛奶(任意!),每周成本为c_i(1~5000),每周出货 y_i:出货可以使用该周生产的,也可以用之前的储存的牛奶,每周存储 每单位牛奶需要 S 价格.问,N周最小的成本是多少? 题解:贪心策略,维持每周 的最低单位成本,本周的单位成本 为 min(上周单位成本 + 存储S,本周成本) AC代码: #include <iostream> #include <cstdio> #include &

poj 2393 Yogurt factory(dp+贪心)

奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S.求总体最低成本. 贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的.于是该周单位成本可能为上一周的单位成本加上储存费,也可能为该周的单位成本. 1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #in

bzoj 1680\1740 : [Usaco2005 Mar]Yogurt factory 贪心 双倍经验

1680: [Usaco2005 Mar]Yogurt factory 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 com

poj_2393 Yogurt factory 贪心

Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16669   Accepted: 8176 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

poj Yogurt factory (贪心水题)

# include <stdio.h> # include <string.h> # include <algorithm> using namespace std; int main() { int i,n,s; __int64 sum ; int cost[10010],num[10010]; while(~scanf("%d%d",&n,&s)) { for(i=0;i<n;i++) scanf("%d%d&qu