码迷,mamicode.com
首页 > 其他好文 > 详细

POJ 2393 Yogurt factory(简单贪心)

时间:2014-11-11 22:55:16      阅读:297      评论:0      收藏:0      [点我收藏+]

标签:style   http   io   ar   os   sp   for   on   ef   

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 namespace std;

int main(int argc, char *argv[])
{

    int N, S;
    cin >> N >> S;
    int P = 5000;
    long long costs = 0;
    for (int i = 0; i < N; ++i)
    {
        int C, Y;
        cin >> C >> Y;
        P = min(P + S, C);
        costs += P * Y;
    }
    cout << costs << endl;

    return 0;
}


POJ 2393 Yogurt factory(简单贪心)

标签:style   http   io   ar   os   sp   for   on   ef   

原文地址:http://blog.csdn.net/acm_10000h/article/details/41018171

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!