POJ - 3257 Cow Roller Coaster (背包)
题目大意:要用N种材料建一条长为L的路,如今给出每种材料的长度w。起始地点x。发费c和耐久度f
问:在预算为B的情况下,建好这条路的最大耐久度是多少
解题思路:背包问题
dp[i][j]表示起始地点为i。发费为j的最大耐久度
可得转移方程
dp[i + w][j + c] = max(dp[i + w][j + c],dp[i][j] + f)
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define maxl 1010
#define maxn 10010
#define INF 0x3f3f3f3f
int L, N, B;
int dp[maxl][maxl];
struct component {
int x, w, f, c;
}com[maxn];
int cmp(const component a, const component b) {
return a.x < b.x;
}
void init() {
for(int i = 0; i < N; i++)
scanf("%d%d%d%d", &com[i].x, &com[i].w, &com[i].f, &com[i].c);
sort(com, com + N, cmp);
}
void solve() {
memset(dp, -1, sizeof(dp));
dp[0][0] = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j <= B - com[i].c; j++)
if(dp[com[i].x][j] != -1) {
dp[com[i].x + com[i].w][j + com[i].c] = max(dp[com[i].x + com[i].w][j + com[i].c], dp[com[i].x][j] + com[i].f) ;
}
}
int ans = -1;
for(int i = 0; i <= B; i++)
if(dp[L][i] != INF)
ans = max(ans, dp[L][i]);
printf("%d\n", ans);
}
int main() {
while(scanf("%d%d%d", &L, &N, &B) != EOF ) {
init();
solve();
}
return 0;
}
POJ - 3257 Cow Roller Coaster (背包)的更多相关文章
- BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
- 洛谷P2854 [USACO06DEC]牛的过山车Cow Roller Coaster
P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want you ...
- 【题解】P2854 [USACO06DEC]牛的过山车Cow Roller Coaster
P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want you ...
- bzoj1649 / P2854 [USACO06DEC]牛的过山车Cow Roller Coaster
P2854 [USACO06DEC]牛的过山车Cow Roller Coaster dp 对铁轨按左端点排个序,蓝后就是普通的二维dp了. 设$d[i][j]$为当前位置$i$,成本为$j$的最小花费 ...
- bzoj1649 [Usaco2006 Dec]Cow Roller Coaster
Description The cows are building a roller coaster! They want your help to design as fun a roller co ...
- BZOJ——1649: [Usaco2006 Dec]Cow Roller Coaster
http://www.lydsy.com/JudgeOnline/problem.php?id=1649 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 7 ...
- P2854 [USACO06DEC]牛的过山车Cow Roller Coaster
题目描述 The cows are building a roller coaster! They want your help to design as fun a roller coaster a ...
- 【BZOJ】1649: [Usaco2006 Dec]Cow Roller Coaster(dp)
http://www.lydsy.com/JudgeOnline/problem.php?id=1649 又是题解... 设f[i][j]表示费用i长度j得到的最大乐趣 f[i][end[a]]=ma ...
- [POJ 2184]--Cow Exhibition(0-1背包变形)
题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS Memory Limit: 65536K Total S ...
随机推荐
- JavaScript扩展运算符(...)
对象的扩展运算符 扩展运算符是三个点(...).用于取出参数对象的所有可遍历属性,然后拷贝到当前对象之中. 如上图所示,新建了一个对象a,然后通过扩展运算符将其属性x,y一并拷贝到b对象中. 合并两个 ...
- docker(二):CentOS安装docker
前置条件 1. CentOS 7:要求系统为64位.系统内核版本为 3.10 以上 使用如下命令,查看机器配置 lsb_release -a uname -a 2. 关闭防火墙 systemctl s ...
- Python基本数据类型之字典dict
字典dict 是一个键(key)值(value)对,结构为{},大括号 创建字典 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 info = { # k ...
- Sql中Convert日期格式
CONVERT(data_type,expression[,style]) convert(varchar(10),字段名,转换格式) 说明:此样式一般在时间类型(datetime,smalldate ...
- [Offer收割]编程练习赛38
漏写的数字 #pragma comment(linker, "/STACK:102400000,102400000") #include<stdio.h> #inclu ...
- Promise API 简介
Promise API 简介 译者注: 到处是回调函数,代码非常臃肿难看, Promise 主要用来解决这种编程方式, 将某些代码封装于内部. Promise 直译为"承诺",但一 ...
- Python 中文注释报错解决方法
代码中一旦有了中文注释便会报错. 原因 如果文件里有非ASCII字符,需要在第一行或第二行指定编码声明. 解决方法 在第一行或是第二行加入这么一句# -- coding: utf-8 -- 完美解决
- params可变参数、SqlCommand.Parameters.add()方法
namespace params可变参数{ class Program { static void Main(string[] args) { int[] num = {66,99,55,44, }; ...
- java RPC系列之二 HTTPINVOKER
java RPC系列之二 HTTPINVOKER 一.java RPC简单的汇总 java的RPC得到技术,基本包含以下几个,分别是:RMI(远程方法调用) .Caucho的Hessian 和 Bu ...
- 3 Python+Selenium的元素定位方法(id、class name、name、tag name)
[环境] Python3.6+selenium3.0.2+IE11+Win7 [定位方法] 1.通过ID定位 方法:find_element_by_id('xx') 2.通过name定位 方法:fin ...