题目大意:要用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 (背包)的更多相关文章

  1. BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )

    有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...

  2. 洛谷P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

    P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want you ...

  3. 【题解】P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

    P2854 [USACO06DEC]牛的过山车Cow Roller Coaster 题目描述 The cows are building a roller coaster! They want you ...

  4. bzoj1649 / P2854 [USACO06DEC]牛的过山车Cow Roller Coaster

    P2854 [USACO06DEC]牛的过山车Cow Roller Coaster dp 对铁轨按左端点排个序,蓝后就是普通的二维dp了. 设$d[i][j]$为当前位置$i$,成本为$j$的最小花费 ...

  5. 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 ...

  6. 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 ...

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

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

  9. [POJ 2184]--Cow Exhibition(0-1背包变形)

    题目链接:http://poj.org/problem?id=2184 Cow Exhibition Time Limit: 1000MS   Memory Limit: 65536K Total S ...

随机推荐

  1. php 日期格式化

    date('Y-m-d H:i:s',time()); 2014-09-01 05:06:01 date(' y-n-j G:i:s',time()); 14-9-1 5:06:01 mktime(h ...

  2. Elasticsearch日志收集

    Install pip if necessary curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py&q ...

  3. zgb老师关于java集合的总结

    数组:存多个数据 操作不便集合(Collection ):存多个数据 管理多个数据 提供更为方便的操作Iterator:专门针对集合 进行迭代List:有序的 允许重复的元素ArrayList:底层数 ...

  4. Windows环境下使用强大的wget工具

    安装 下载[http://www.interlog.com/~tcharron/wgetwin.html] 解压到目录 比如我解压到D:\Tool\wget 添加wget环境变量,这样使用就更方便了, ...

  5. ShowDialog函数与Form的Activated函数同时使用的陷阱

    当我们需要在form启动之时,焦点显示在特定的控件“btn”上,我们可以先将btn的TabIndex设为0,然后要确保它visible=true,最后在Form的Activated事件方法中btn.G ...

  6. 派遣函数IRP

    派遣函数是Windows驱动程序中的重要概念.驱动程序的主要功能是负责处理I/O请求,其中大部分I/O请求是在派遣函数中处理的. 用户模式下所有对驱动程序的I/O请求,全部由操作系统转换为一个叫做IR ...

  7. damn selenium

    Selenium+Python [ˈpaɪθən] 0.Selenium安装 pip install selenium 1.打开了浏览器,后边什么都不干了 需要将浏览器驱动放置在环境变量的目录下. 2 ...

  8. 完美解决ios10及以上Safari无法禁止缩放的问题

    移动端web缩放有两种: 1.双击缩放: 2.双指手势缩放. 在iOS 10以前,iOS和Android都可以通过一行meta标签来禁止页面缩放 <meta content="widt ...

  9. GoogleMap 获取自己的数字证书API key的步骤

    http://dreamylights.blog.51cto.com/1163218/1360759 1. 进入到Google APIs Console页面 https://code.google.c ...

  10. VS2012 编译 boost1.53/ boost1.49

    原文链接:http://blog.csdn.net/ly131420/article/details/8904122 一.下载Boost库 boost_1_53_0.zip   (http://www ...