题目大意:要用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. LinkedHashMap做缓存

    项目上需要写一个缓存,这样就不需要频繁地访问数据库,我使用的是 //缓存 private final Map<String, JSONArray> schemaCache = new Li ...

  2. golang iris html/temple

    在使用golang的模板语法的过程中遇见自动转义问题(或者以我的理解下发的富文本html代码不是template.html类型,而是string类型),需要强制转型 func unescaped(x ...

  3. OpenCASCADE 包说明

    转载地址:http://www.cppblog.com/eryar/archive/2012/06/30/180916.html 一.简介 Introduction to Package gp gp是 ...

  4. springmvc-servlet.xml 第二种选择

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  5. ASCII和ASCII扩展表

  6. WPF 标题栏 右键窗口标题添加关于对话框

    /// <summary> /// wpf标题栏 右键菜单 中添加新项 /// </summary> public partial class MainWindow : Win ...

  7. linux openSSL 安装

    包名:openssh-server apt安装:apt-get install openssh-server yum安装:yum install openssh-server 服务启动:service ...

  8. java线程入门知识

    为什么需要多线程? . 模型的简化,如某些程序是由多个相对独立任务的运行: . 图形界面的出现,输入.输出的阻塞 . 多核CPU的更好利用 . 异步行为的需要 Java多线程的特性: . 程序的入口m ...

  9. HttpServletRequest二三事

    缘由 在项目中,闲来无聊写了个bug LOGGER.info("前端请求,request:{}",JSON.toJSONString(request)); 好像还好是吧,来我告诉你 ...

  10. Swfit4.0中JSON与模型原生互转(JSONEncoder/JSONDecoder的使用)

    在Objective-C中,苹果并没有提供JSON转模型(模型转JSON)的接口,往往在开中需要添加第三库来处理JSON数据,比如:JsonModel.MJExtension.Mantle.JsonK ...