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)
http://www.lydsy.com/JudgeOnline/problem.php?id=1649 又是题解... 设f[i][j]表示费用i长度j得到的最大乐趣 f[i][end[a]]=ma ...
- POJ 3660 Cow Contest [Floyd]
POJ - 3660 Cow Contest http://poj.org/problem?id=3660 N (1 ≤ N ≤ 100) cows, conveniently numbered 1. ...
- poj 1985 Cow Marathon 【树的直径】
求树的直径 /* POJ:1985 Cow Marathon 2014/10/12/21:18 Yougth*/ #include <cstdio> #include <iostre ...
- poj 2063 Investment(01背包变形)
http://poj.org/gotoproblem?pid=2063 (1)上限 m 一直上升的 n 次01背包问题,比一般的01背包多了一重循环: (2)本题出现了各种错误:1)刚开始,没注意 m ...
- POJ 3624 Charm Bracelet 0-1背包
传送门:http://poj.org/problem?id=3624 题目大意:XXX去珠宝店,她需要N件首饰,能带的首饰总重量不超过M,要求不超过M的情况下,使首饰的魔力值(D)最大. 0-1背包入 ...
- poj 1252 Euro Efficiency (01背包变形)
http://poj.org/gotoproblem?pid=1252 (1)不是单纯的01背包问题,硬币有去有回(即有正有负),这使得用想买你的解法,上限难以确定,所以我开了dp[10000]的数组 ...
- poj 3624 Charm Bracelet (01背包)
题目链接:http://poj.org/problem?id=3624 //典型01背包问题 //状态转移方程dp[i][j]=max(dp[i-1][j],dp[i-1][j-w[i]]+d[i]) ...
- POJ 3660 Cow Contest 传递闭包+Floyd
原题链接:http://poj.org/problem?id=3660 Cow Contest Time Limit: 1000MS Memory Limit: 65536K Total Subm ...
- [POJ 3270]Cow Sorting
Description Farmer John's N (1 ≤ N ≤ 10,000) cows are lined up to be milked in the evening. Each cow ...
最新文章
- PyQt主窗体设置停靠窗口(QDockWidget)的叠加顺序
- http://www.cnblogs.com/dolphin0520/p/3949310.html
- ui和android有联系,Android单位换算与UI适配
- DCMTK:工作清单数据库测试程序
- Angular应用只执行指定单元测试的小技巧
- spring boot 实战
- centos mysql无法启动 sock_【零基础学云计算】MYSQL的主从复制、读写分离
- 蚂蚁愚人节视频透露的真相:区块链只有科技巨头才玩得起?
- 论文笔记7 --(ReID)Video-based Person Re-identification via Self Paced Weighting
- Discarding previously cached master state
- centos 零碎学习小记 11.
- 浅谈数字后端工程师的工作
- 管理的常识(2):什么是领导
- Hyperf基础使用
- HackerRank 题目目录
- 数据中心交换机与普通交换机有什么不同?
- Caffe Prototxt 特殊层系列:Crop Layer
- Django学习日志三:模型层
- 【Python学习笔记】简单调用百度API应用
- Python利用Face++实现身份证件图片识别