USACO Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II
JDOJ 2671: USACO 2010 Jan Silver 2.Buying Feed, II
Description
Farmer John needs to travel to town to pick up K (1 <= K <= 100)
The county feed lot has N (1 <= N <= 100) stores (convenientlynumbered 1..N) that sell feed. Each store is located on a segmentof the X axis whose length is E (1 <= E <= 350). Store i is atlocation X_i (0 < X_i < E) on the number line and can sell FJ asmuch as F_i (1 <= F_i <= 100) pounds of feed at a cost of C_i (1<= C_i <= 1,000,000) cents per pound. Amazingly, a given point onthe X axis might have more than one store.
What is the minimum amount FJ has to pay to buy and transport theK pounds of feed? FJ knows there is a solution.
It is best for FJ to buy one pound of feed from both the second andthird stores. He must pay two cents to buy each pound of feed fora total cost of 4. When FJ travels from 3 to 4 he is moving 1 unitof length and he has 1 pound of feed so he must pay 1*1 = 1 cents.
The total cost is 4+1+2 = 7 cents.
Input
* Line 1: Three space-separated integers: K, E, and N
* Lines 2..N+1: Line i+1 contains three space-separated integers: X_i,
F_i, and C_i
Output
* Line 1: A single integer that is the minimum cost for FJ to buy and
transport the feed
Sample Input
2 5 3 3 1 2 4 1 2 1 1 1
Sample Output
7
题目翻译:
FJ开车去买K份食物,如果他的车上有X份食物。每走一里就花费X元。 FJ的城市是一条线,总共E里路,有E+1个地方,标号0~E。 FJ从0开始走,到E结束(不能往回走),要买K份食物。 城里有N个商店,每个商店的位置是X_i(一个点上可能有多个商店),有F_i份食物,每份C_i元。 问到达E并买K份食物的最小花费。
题解:
转化成多重背包问题求解。
多重背包就是完全背包的升级版,从每种物品有无限件可以用变成有一个固定的数量,也可以用二进制优化一下,详见具体讲解。
本题可以采用这种动态规划的方式AC
代码:
#include<cstdio>
#include<algorithm>
using namespace std;
int dp[105];
int main()
{
int n,e,k,x,f,c;
scanf("%d%d%d",&k,&e,&n);
for(int i=1;i<=k;i++)
dp[i]=1<<30;
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&f,&c);
for(int j=k;j>=1;j--)
for(int l=1;l<=f;l++)
{
if(l>j)
break;
dp[j]=min(dp[j],dp[j-l]+l*(c+e-x));
}
}
printf("%d",dp[k]);
return 0;
}
USACO Buying Feed, II的更多相关文章
- 2020: [Usaco2010 Jan]Buying Feed, II
2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec Memory Limit: 64 MBSubmit: 220 Solved: 162[ ...
- 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II
洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...
- 【P2616】 【USACO10JAN】购买饲料II Buying Feed, II
P2616 [USACO10JAN]购买饲料II Buying Feed, II 题目描述 Farmer John needs to travel to town to pick up K (1 &l ...
- 【BZOJ】2020: [Usaco2010 Jan]Buying Feed, II (dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=2020 和背包差不多 同样滚动数组 f[j]表示当前位置j份食物的最小价值 f[j]=min(f[j- ...
- BZOJ 2020 [Usaco2010 Jan]Buying Feed,II:贪心【定义价值】
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2020 题意: FJ开车去买K份食物. 如果他的车上有X份食物,每走一里就花费X元. FJ的 ...
- BZOJ2020: [Usaco2010 Jan]Buying Feed II
[传送门:BZOJ2020] 简要题意: 约翰开车回家,遇到了双十一节,那么就顺路买点饲料吧.回家的路程一共有E 公里,这一路上会经过N 家商店,第i 家店里有Fi 吨饲料,售价为每吨Ci 元.约翰打 ...
- ACM BUYING FEED
BUYING FEED 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 Farmer John needs to travel to town to pick up ...
- BUYING FEED
Problem F: F BUYING FEED Description Farmer John needs to travel to town to pick up K (1 <= K < ...
- USACO Buying Hay
洛谷 P2918 [USACO08NOV]买干草Buying Hay https://www.luogu.org/problem/P2918 JDOJ 2592: USACO 2008 Nov Sil ...
随机推荐
- 企业级Nginx负载均衡与keepalived高可用实战(二)keepalived篇
1.Keepalived高可用软件 1.1.Keepalived介绍 Keepalived软件起初是专门为LVS负载均衡软件设计的,用来管理并监控LVS集群系统中各个服务节点的状态,后来又加入了可以实 ...
- 前后台$.post交互并返回JSON对象
1.前台代码: $.post(url,{"blogId":blogId},function(reData){ if(reData.state=="success" ...
- System.Windows.Forms.Control.CheckForIllegalCrossThreadCalls = false
多线程程序中,新创建的线程不能访问UI线程创建的窗口控件,这时如果想要访问窗口的控件,发现无法对其控制. 这时可将窗口构造函数中的CheckForIllegalCrossThreadCalls设置为f ...
- fancybit个人简介
程序员一枚 熟悉C C++ C# js lua等多种常见开发语言 熟悉Unity游戏开发 node.js pomelo和C# scut 网游后端框架 做过.net和php网站后端 二次元文化爱好者 有 ...
- 一般处理程序Session
1.要在一般处理程序中获取其他页面的session值,需要引用名空间: using System.Web.SessionState; 2.然后继承一个接口:IRequiresSessionState ...
- asp.net 版本一键升级,后台直接调用升级脚本
应客户需求,要求实现一个版本一键升级的功能,咨询过同事之后弄了个demo出来,后台代码如下: //DBConnModelInfo:连接字符串的对象 (包含数据库实例名,数据库名,登陆名,登陆密码) p ...
- ASP.NET Core部署IIS问题总结
部署准备工作 1.服务器开启添加IIS相关功能 1.1. 点击windows搜索到 “启用或关闭windows功能” 1.2 选择添加IIS的部分功能, 如下图所示 2.进入IIS,添加已经发布的 ...
- 写给自己的 SOA 和 RPC 理解
1.SOA SOA(Service-Oriented Architecture)面向服务架构,将应用程序不同功能单元(称为服务)进行拆分,并通过这些服务之间定义良好的接口和契约联系起来. SOA 不是 ...
- PHP上传图片基本代码示例
一.HTML代码如下: <form name="form2" method="post" action="?type=add" enc ...
- vue-quill-editor富文本编辑器 中文翻译组件,编辑与展示
vue项目中用到了富文本编辑器,网上找了一些,觉得vue-quill-editor最好用, ui简洁,功能也好配,够用了,文档不好读,有些小细节需要自己注意,我懒得分析,就封装成了组件 大家用的时候直 ...