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. fork()创建子进程

    fork()系统调用是Unix下以自身进程创建子进程的系统调用,一次调用,两次返回,如果返回是0,则是子进程,如果返回值>0,则是父进程(返回值是子进程的pid) 在fork()的调用处,整个父 ...

  2. 【Oracle】oracle利用正则表达式拆分IP地址

    使用oracle提供的regexp_substr()函数,对将IPV4地址分成4段: select v.ip as ip_address, regexp_substr(v.ip,,) as A, re ...

  3. [NOIP2011]聪明的质监员 题解

    题目大意: 额--貌似蛮清晰的,就不赘述了. 思路: 首先不难发现M越大Y越小,因此可以二分答案(方向不要弄错),二分出最小的不小于S的Y即可.而计算Y时可用前缀和O(n+m)求得.两种边界情况也要考 ...

  4. CentOS6.7安装RabbitMQ3.6.5

    1.安装所有依赖包yum install -y gcc ncurses ncurses-base ncurses-devel ncurses-libs ncurses-static ncurses-t ...

  5. type of 操作符和instanceof操作符的区别以及使用方法

    经常见到用typeof和instanceof检测一个变量类型,作为前端小白经常不知道这两者具体的详细用法和区别,今天就整理一下谨记! javaScript中有6中数据类型: 1.Undefinde 2 ...

  6. uri不能处理结尾为点的url的问题

    最近需要和某公司进行接口对接,发现用WebClient获取URL结尾带.的资源,会出404错误.但是用IE还有其它浏览器访问此资源,还能找到它.很神奇. 于是,我百度了,找到的一堆都是说此url不规范 ...

  7. linux errno使用

    errno详解 http://blog.csdn.net/wang_517766334/article/details/7561495 #include <errno.h> 就可以直接打印 ...

  8. jquery ui dialog autofocus 去掉默认第一个元素获取焦点

    经常在dialog窗口中第一个元素为日期控件时,打开窗口则会自动显示日期下拉框. 解决办法:在dialog的open事件中,设置父对象获得焦点. p1_dialog_seniorSearch.dial ...

  9. Wordpress 所有hoor列表

    d 在插件加载的时候执行 wp_footer 加载页面底部时执行 admin_menu 加载管理员菜单时执行 wp_head 在body标签的开始添加html内容 after_setup_theme ...

  10. (转)基于socket的TCP和UDP编程

    一.概述 TCP(传输控制协议)和UDP(用户数据报协议是网络体系结构TCP/IP模型中传输层一层中的两个不同的通信协议. TCP:传输控制协议,一种面向连接的协议,给用户进程提供可靠的全双工的字节流 ...