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 ...
随机推荐
- day63-webservice 05.发布接口实现类的webservice
package com.rl.cxf.client; import com.rl.inter.HI; import com.rl.inter.HIService; public class HiInt ...
- [CSharp] C#开源大全
商业协作和项目管理平台-TeamLab 网络视频会议软件-VMukti 驰骋工作流程引擎-ccflow [免费]正则表达式测试工具-Regex-Tester Windows-Phone-7-SDK E ...
- 关于java1.8中LocalDateTime实现日期,字符串互转小坑。
今天无聊,来看了下1.8的时间类型LocalDateTime,当想把字符串转成LocalDateTime的时候报错!! java.time.format.DateTimeParseException: ...
- 从 Zero 到 Hero ,一文掌握 Python--转
https://www.oschina.net/translate/learning-python-from-zero-to-hero 第一个问题,什么是 Python ?根据 Python 之父 G ...
- 实验6 Bezier曲线生成
1.实验目的: 了解曲线的生成原理,掌握几种常见的曲线生成算法,利用VC+OpenGL实现Bezier曲线生成算法. 2.实验内容: (1) 结合示范代码了解曲线生成原理与算法实现,尤其是Bezier ...
- Kattis - Different Distances
Input The input file contains up to 10001000 test cases, each of which contains five real numbers, x ...
- pycharm一些快捷键
1.鼠标方法在内建函数上,Ctrl+B,看内建函数的定义 2.pycharm单行和多行注释快捷键 单多行注释就一个组合键:选中+Ctrl+/ 3.Python代码块批量添加Tab缩进 按Ta ...
- Pyhton学习——Day1
1.什么是机器码?什么是字节码?机器码(machine code),学名机器语言指令,有时也被称为原生码(Native Code),是电脑的CPU可直接解读的数据. 通常意义上来理解的话,机器码就是计 ...
- 如何分页爬取数据--beautisoup
'''本次爬取讲历史网站'''#!usr/bin/env python#-*- coding:utf-8 _*-"""@author:Hurrican@file: 分页爬 ...
- Python笔记18-----函数收集参数
1.收集参数(参数前面加*): def test1(param1,*params): print(param1) print(params) 调用:test1(1,2,3,4) 结果:1 (2,3,4 ...