poj-2393 Yogurt factory (贪心)
http://poj.org/problem?id=2393
奶牛们有一个工厂用来生产奶酪,接下来的N周时间里,在第i周生产1 单元的奶酪需要花费ci,同时它们也有一个储存室,奶酪放在那永远不会坏,并且可以无限放,每一单元奶酪放在那的价格恒定为每周s。然后奶牛在第i周会交付顾客yi的奶酪,让你求最小花费。
因为第i周的奶酪,可以在第i周生产,也可以在前几周生产,然后储存。通过把s转化为花费,跟原有花费去比较,取一个最小值,这样从头到尾,每一周都可以取得一个花费的最小值。贪心求解。
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <string>
#include <set>
#include <functional>
#include <numeric>
#include <sstream>
#include <stack>
#include <map>
#include <queue> #define CL(arr, val) memset(arr, val, sizeof(arr)) #define ll long long
#define inf 0x7f7f7f7f
#define lc l,m,rt<<1
#define rc m + 1,r,rt<<1|1
#define pi acos(-1.0) #define L(x) (x) << 1
#define R(x) (x) << 1 | 1
#define MID(l, r) (l + r) >> 1
#define Min(x, y) (x) < (y) ? (x) : (y)
#define Max(x, y) (x) < (y) ? (y) : (x)
#define E(x) (1 << (x))
#define iabs(x) (x) < 0 ? -(x) : (x)
#define OUT(x) printf("%I64d\n", x)
#define lowbit(x) (x)&(-x)
#define Read() freopen("a.txt", "r", stdin)
#define Write() freopen("b.txt", "w", stdout);
#define maxn 1000000000
#define N 10010
using namespace std; int p[N],q[N];
int main()
{
//Read();
//Write()
int n,s;
long long sum=;
while(~scanf("%d%d",&n,&s))
{
sum=;
for(int i=;i<n;i++) scanf("%d%d",&p[i],&q[i]);
for(int i=;i<n;i++)
{
p[i]=min(p[i-]+s,p[i]);
}
for(int i=;i<n;i++)
{
sum+=p[i]*q[i];
}
printf("%lld\n",sum);
}
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
http://poj.org/problem?id=2393 Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submis ...
- 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_2393 Yogurt factory 贪心
Yogurt factory Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16669 Accepted: 8176 D ...
- POJ 2373 Yogurt factory
简单DP. 这周所用的实际花费是上一周的花费+S与这周费用的较小值. #include<cstdio> #include<cstring> #include<cmath& ...
- POJ-2393 Yogurt factory 贪心问题
题目链接:https://cn.vjudge.net/problem/POJ-2393 题意 有一个生产酸奶的工厂,还有一个酸奶放在其中不会坏的储存室 每一单元酸奶存放价格为每周s元,在接下来的N周时 ...
- 百炼 POJ2393:Yogurt factory【把存储费用用递推的方式表达】
2393:Yogurt factory 总时间限制: 1000ms 内存限制: 65536kB 描述 The cows have purchased a yogurt factory that m ...
随机推荐
- 【转载】Web应用工作原理
问题描述: Web应用工作原理 问题解决: 参考资料:http://blog.csdn.net/lcore/article/details/8964642 ...
- O(V*n)的多重背包问题
多重背包问题: 有n件物品,第i件价值为wi,质量为vi,有c1件,问,给定容量V,求获得的最大价值. 朴素做法: 视为0,1,2,...,k种物品的分组背包 [每组只能选一个] f[i][j]=Ma ...
- 博弈论入门小结 分类: ACM TYPE 2014-08-31 10:15 73人阅读 评论(0) 收藏
文章原地址:http://blog.csdn.net/zhangxiang0125/article/details/6174639 博弈论:是二人或多人在平等的对局中各自利用对方的策略变换自己的对抗策 ...
- windows 上配置solr5.2.1+solr4.3+中文分词器
搭建5.2.1 1.下载 Tomcat解压后的目录为 D:\Program Files\Apache Software Foundation\apache-tomcat-8.0.22 solr解压后的 ...
- 小试牛刀MVC简单网页
上次我们创建了第一个MVC的网站,没用下,这次就简单来运行下,首先大家要去理解下MVC模式到底什么关系.在这里我就不多说,直接创建一个网页,用来显示一些数据,数据库的话我就先简单用这样创建先,为了方便 ...
- LUCAS 定理
原来一张图就就能证明:C(N,M)%P,p是素数. 简直太炫酷 先膜拜会 #include<iostream>#include<cstdio>#include<ctime ...
- PHP soap Web Service 使用SoapDiscovery.class.php 生成wsdl文件
PHP soap web service 使用wsdl文件 demo: ============================================================== 服 ...
- (转)Engineering Productivity
(转)http://www.wandoujia.com/blog/from-qa-to-ep 这个文章之前读过,很不错.今天再读,有不一样的感受!推荐下. 下面是几段摘录: EP 是什么 说到这里,E ...
- Sqli-labs less 56
Less-56 与less54.55形式是一致的,我们关注sql语句, $sql="SELECT * FROM security.users WHERE id=('$id') LIMIT 0 ...
- PHP7安装笔记
PHP7安装笔记 时间 -- :: 喵了个咪 原文 http://www.hdj.me/php7-install-note 主题 PHP # 安装mcrypt yum install -y php-m ...