洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II

洛谷传送门

JDOJ 2671: USACO 2010 Jan Silver 2.Buying Feed, II

JDOJ传送门

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的更多相关文章

  1. 2020: [Usaco2010 Jan]Buying Feed, II

    2020: [Usaco2010 Jan]Buying Feed, II Time Limit: 3 Sec  Memory Limit: 64 MBSubmit: 220  Solved: 162[ ...

  2. 洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II

    洛谷 P2616 [USACO10JAN]购买饲料II Buying Feed, II https://www.luogu.org/problemnew/show/P2616 题目描述 Farmer ...

  3. 【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 ...

  4. 【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- ...

  5. BZOJ 2020 [Usaco2010 Jan]Buying Feed,II:贪心【定义价值】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=2020 题意: FJ开车去买K份食物. 如果他的车上有X份食物,每走一里就花费X元. FJ的 ...

  6. BZOJ2020: [Usaco2010 Jan]Buying Feed II

    [传送门:BZOJ2020] 简要题意: 约翰开车回家,遇到了双十一节,那么就顺路买点饲料吧.回家的路程一共有E 公里,这一路上会经过N 家商店,第i 家店里有Fi 吨饲料,售价为每吨Ci 元.约翰打 ...

  7. ACM BUYING FEED

    BUYING FEED 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 Farmer John needs to travel to town to pick up ...

  8. BUYING FEED

    Problem F: F BUYING FEED Description Farmer John needs to travel to town to pick up K (1 <= K < ...

  9. USACO Buying Hay

    洛谷 P2918 [USACO08NOV]买干草Buying Hay https://www.luogu.org/problem/P2918 JDOJ 2592: USACO 2008 Nov Sil ...

随机推荐

  1. 第02组 Alpha冲刺(4/6)

    队名:無駄無駄 组长博客 作业博客 组员情况 张越洋 过去两天完成了哪些任务 摸鱼 提交记录(全组共用) 接下来的计划 沟通前后端成员,监督.提醒他们尽快完成各自的进度 学习如何评估代码质量 准备Al ...

  2. SpringBoot-dubbo自定义负载均衡实现简单灰度

    本文介绍如何利用dubbo自定义负载实现简单灰度(用户纬度,部分用户访问一个服务,其余访问剩余服务). 其实在这之前,对dubbo了解的也不是很多,只是简单的使用过,跑了几个demo而已,但是得知接下 ...

  3. (三)golang--执行流程分析

    XXX.go--go build XXX.go--XXX.exe XXX.go--go run XXX.go 两种方式的区别:(1)如果我们先编译生成了可执行文件,那么我们可以将该可执行文件拷贝到没g ...

  4. microbit之mpython的API

    附录:常用API函数汇总 一.显示 display.scroll("Hello, World!") 在micro:bit点阵上滚动显示Hello, World!,其中Hello, ...

  5. XMLHttpRequest原生方法

    时间久了,在工作中会有很多方法和见解. 随着时间的推移,慢慢的写的代码越来越多,封装分方法也越来越多,为的是方便后续工作,加快开发效率! 与此同时,我们会相应的去找一些插件,来代替我们在开发过程中执行 ...

  6. vue 复制文本到剪切板上

    1.下载clipboard.js npm install vue-clipboard2 --save 2.引入,可以在mian.js中全局引入也可以在单个vue中引入 import Clipboard ...

  7. xunsearch强制刷新

    $index = $xs->index; $index->flushLogging(); 等价于 util/Indexer.php --flush-log demo

  8. 简要介绍Active Learning(主动学习)思想框架,以及从IF(isolation forest)衍生出来的算法:FBIF(Feedback-Guided Anomaly Discovery)

    1. 引言 本文所讨论的内容为笔者对外文文献的翻译,并加入了笔者自己的理解和总结,文中涉及到的原始外文论文和相关学习链接我会放在reference里,另外,推荐读者朋友购买 Stephen Boyd的 ...

  9. 前后端分离项目Vue+drf开发部署总结

    思维导图xmind文件:https://files-cdn.cnblogs.com/files/benjieming/%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A ...

  10. powershell ssh-agent 无法工作

    windows 10的powershell已经支持open-ssh的功能. 但是运行get-service ssh-agent似乎显示的stopped. 如下: PS C:\WINDOWS\syste ...