奶牛们建了一家酸奶厂,在N周内每周需要出货Y_i单位酸奶,第i周成本为C_i,储存费为每周S。求总体最低成本。

贪心策略是维持每周的最低单位成本,每周可能用上周剩下的,也可能生产新的。于是该周单位成本可能为上一周的单位成本加上储存费,也可能为该周的单位成本。

 #pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<math.h>
#include<algorithm>
#include<queue>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<stdlib.h>
#include <stack>
using namespace std;
#define PI acos(-1.0)
#define max(a,b) (a) > (b) ? (a) : (b)
#define min(a,b) (a) < (b) ? (a) : (b)
#define ll long long
#define eps 1e-10
#define MOD 1000000007
#define N 10006
#define inf 1e12
int n,s;
int c[N],y[N];
int main()
{
while(scanf("%d%d",&n,&s)==){
for(int i=;i<n;i++){
scanf("%d%d",&c[i],&y[i]);
}
ll 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("%I64d\n",ans);
}
return ;
}

poj 2393 Yogurt factory(dp+贪心)的更多相关文章

  1. POJ 2393 Yogurt factory【贪心】

    POJ 2393 题意: 每周可以生产牛奶,每周生产的价格为Ci,每周需要上交的牛奶量Yi,你可以选择本周生产牛奶,也可选择提前几周生产出存储在仓库中(仓库无限大,而且保质期不考虑),每一周存仓库牛奶 ...

  2. poj 2393 Yogurt factory

    http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submis ...

  3. POJ 2393 Yogurt factory 贪心

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

  4. 贪心问题 POJ 2393 Yogurt factory

    题目:http://poj.org/problem?id=2393 题意:N周,每周生成牛奶(任意!),每周成本为c_i(1~5000),每周出货 y_i:出货可以使用该周生产的,也可以用之前的储存的 ...

  5. 【BZOJ】1680: [Usaco2005 Mar]Yogurt factory(贪心)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1680 看不懂英文.. 题意是有n天,第i天生产的费用是c[i],要生产y[i]个产品,可以用当天的也 ...

  6. POJ2393 Yogurt factory 【贪心】

    Yogurt factory Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6821   Accepted: 3488 De ...

  7. POJ 2373 Yogurt factory

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

  8. BZOJ 1680 [Usaco2005 Mar]Yogurt factory:贪心【只用考虑上一个】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1680 题意: 在接下来的n周内,第i周生产一吨酸奶的成本为c[i],订单为y[i]吨酸奶. ...

  9. bzoj 1680: [Usaco2005 Mar]Yogurt factory【贪心】

    贪心,一边读入一边更新mn,用mn更新答案,mn每次加s #include<iostream> #include<cstdio> using namespace std; in ...

随机推荐

  1. 诺基亚HERE地图

    1.基本图层 2.3D图层 3.卫星图层 4.地形图层 5.在线帮助

  2. UESTC_Little Deer and Blue Cat CDOJ 1025

    In DOTA, there are two Intellegence heroes. One is Enchantress, who is usually called Little Deer by ...

  3. LintCode-A + B 用位操作模拟加法

    class Solution { public: /* * @param a: The first integer * @param b: The second integer * @return: ...

  4. [破解] DRM-内容数据版权加密保护技术学习(中):License预发放实现

    在上一篇文章里实现了对媒体文体的DRM加密,现在一起来实现License的预发放. 所谓预发放就是在播放媒体文件之前先获取到License,License获取成功后,可直接在电脑上进行媒体文件的播放. ...

  5. HibernateTemplate和HibernateDaoSupport

    Spring整合Hibernate后,为Hibernate的DAO提供了两个工具类:HibernateTemplate和HibernateDaoSupport HibernateTemplateHib ...

  6. 产生冠军(set,map,拓扑结构三种方法)

    产生冠军 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  7. 使用公用表表达式(CTE)

    本文来自:http://blog.csdn.net/songjie521/article/details/3321030 通用表表达式(CTEs)是SQL Server 2005的一项新功能.它们类似 ...

  8. VC2010 Working Directory

    VC project setting --〉debug中的working directory指的是工作文件夹在哪里? project属性下,Debug以下的 Working Directory 是为了 ...

  9. Unity sqlite学习笔记一

    1.SQLITE的常识 SQLite是一个开源免费的数据库,一般用于嵌入系统或者小规模的应用软件开发中,你可以像使用Access一样使用它. sqlite的主要优点:零配置(Zero Configur ...

  10. 目标管理剖析与实践– 献给追梦的人 (转)

      好久没写日志了. 最近总算在忙碌的日子中小小的松了一口气, 过来补起这几个月的空缺. 上次写的Cover Letter & Resume 重点诠释 - 深度剖析没想到居然超过了一万的阅读量 ...