题目描述

The cows are building a roller coaster! They want your help to design as fun a roller coaster as possible, while keeping to the budget.

The roller coaster will be built on a long linear stretch of land of length L (1 ≤ L ≤ 1,000). The roller coaster comprises a collection of some of the N (1 ≤ N ≤ 10,000) different interchangable components. Each component i has a fixed length Wi (1 ≤ Wi ≤ L). Due to varying terrain, each component i can be only built starting at location Xi (0 ≤ Xi ≤ L - Wi). The cows want to string together various roller coaster components starting at 0 and ending at L so that the end of each component (except the last) is the start of the next component.

Each component i has a "fun rating" Fi (1 ≤ Fi ≤ 1,000,000) and a cost Ci (1 ≤ Ci ≤ 1000). The total fun of the roller coster is the sum of the fun from each component used; the total cost is likewise the sum of the costs of each component used. The cows' total budget is B (1 ≤ B ≤ 1000). Help the cows determine the most fun roller coaster that they can build with their budget.

奶牛们正打算造一条过山车轨道.她们希望你帮忙,找出最有趣,但又符合预算 的方案. 过山车的轨道由若干钢轨首尾相连,由x=0处一直延伸到X=L(1≤L≤1000)处.现有N(1≤N≤10000)根钢轨,每根钢轨的起点 Xi(0≤Xi≤L- Wi),长度wi(l≤Wi≤L),有趣指数Fi(1≤Fi≤1000000),成本Ci(l≤Ci≤1000)均己知.请确定一 种最优方案,使得选用的钢轨的有趣指数之和最大,同时成本之和不超过B(1≤B≤1000).

输入输出格式

输入格式:

Line 1: Three space-separated integers: L, N and B.

Lines 2..N+1: Line i+1 contains four space-separated integers, respectively: Xi, Wi, Fi, and Ci.

输出格式:

Line 1: A single integer that is the maximum fun value that a roller-coaster can have while staying within the budget and meeting all the other constraints. If it is not possible to build a roller-coaster within budget, output -1.

输入输出样例

输入样例#1: 复制

5 6 10
0 2 20 6
2 3 5 6
0 1 2 1
1 1 1 3
1 2 5 4
3 2 10 2
输出样例#1: 复制

17

说明

Taking the 3rd, 5th and 6th components gives a connected roller-coaster with fun value 17 and cost 7. Taking the first two components would give a more fun roller-coaster (25) but would be over budget.

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 2147483647
const ll INF = 0x3f3f3f3f3f3f3f3fll;
#define ri register int
template <class T> inline T min(T a, T b, T c)
{
return min(min(a, b), c);
}
template <class T> inline T max(T a, T b, T c)
{
return max(max(a, b), c);
}
template <class T> inline T min(T a, T b, T c, T d)
{
return min(min(a, b), min(c, d));
}
template <class T> inline T max(T a, T b, T c, T d)
{
return max(max(a, b), max(c, d));
}
#define pi acos(-1)
#define me(x, y) memset(x, y, sizeof(x));
#define For(i, a, b) for (int i = a; i <= b; i++)
#define FFor(i, a, b) for (int i = a; i >= b; i--)
#define mp make_pair
#define pb push_back
const int maxn = ;
// name*******************************
int f[][];
int L,n,B;
struct node
{
int x,w,f,c;
} a[];
int ans=-;
// function******************************
bool cmp(node a,node b)
{
return a.x<b.x;
} //***************************************
int main()
{
cin>>L>>n>>B;
For(i,,n)
{
cin>>a[i].x>>a[i].w>>a[i].f>>a[i].c;
}
me(f,-);
sort(a+,a++n,cmp);
f[][]=;
For(i,,n)
{
int u=a[i].x;
int v=a[i].x+a[i].w;
FFor(j,B,a[i].c)
{
if(f[u][j-a[i].c]!=-)
f[v][j]=max(f[v][j],f[u][j-a[i].c]+a[i].f);
}
}
For(i,,B)
ans=max(ans,f[L][i]);
cout<<ans; return ;
}

P2854 [USACO06DEC]牛的过山车Cow Roller Coaster的更多相关文章

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

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

  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. [luoguP2854] [USACO06DEC]牛的过山车Cow Roller Coaster(DP + sort)

    传送门 先按照起点 sort 一遍. 这样每一个点的只由前面的点决定. f[i][j] 表示终点为 i,花费 j 的最优解 状态转移就是一个01背包. ——代码 #include <cstdio ...

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

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

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

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

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

  9. 【bzoj1649】Cow Roller Coaster

    傻逼dp题. dp[i][j]表示用了i长度已花费成本j所能得到的价值. 然后枚举一下铁轨随便做了. 不行就sort一下. #include<bits/stdc++.h> #define ...

随机推荐

  1. 记录在window平台安装python的第三库(py,whl)

    在下载python的第三库文件的时候,有些库文件有exe的发行版,但是有些第三库并没有找到针对于window的可执行文件安装包即exe文件,而只有源代码文件即py文件,和whl文件. 下面记录一下在w ...

  2. 原 java调整数据顺序是奇数位于偶数的前面(思路与实现)

    题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. 思路一: 首先这 ...

  3. Memory map of an object array

    Student类: package com.itheima; /* * 自动生成构造方法: * 代码区域右键 -- Source -- Generate Constructors from Super ...

  4. 1java异常详解

    语法错误.编译时错误语义错误.逻辑错误.运行时错误 数组下标越界,c,c++不检查,需要程序员控制. 1.注意:这里说的异常是运行期错误,不包括编译期错误. 2.try尝试运行,catch捕获并处理, ...

  5. CMake中添加Qt模块的合理方法

    https://www.jianshu.com/p/7eeb6f79a275 转载自这里 用CMake来组织的工程中要用Qt首先要设置.找到Qt相关模块.主要是通过find_package这个CMak ...

  6. 聊一聊数组的map、reduce、foreach等方法

    聊聊数组遍历方法 JS 数组的遍历方法有好几个: every some filter foreach map reduce 接下来我们来一个个地交流下. every() arr.every(callb ...

  7. Oracle闪回(FlashBack)数据库

    Flashback Database功能非常类似与RMAN的不完全恢复,它可以把整个数据库回退到过去的某个时点的状态,这个功能依赖于Flashback log日志.比RMAN更快速和高效,因此Flas ...

  8. oracle数据泵备份(Expdp命令)

    Oracle备份方式主要分为数据泵导出备份.热备份与冷备份三种,今天首先来实践一下数据泵备份与还原.数据泵导出/导入属于逻辑备份,热备份与冷备份都属于物理备份.oracle10g开始推出了数据泵(ex ...

  9. SqlServer触发器实现表的级联插入、级联更新

    首先建立两张表,分别为test1与test2,期望在更改test1的时候,test2的相关记录能够同时做出更改.假定test1与test2的表结构相同,如下表所示 name age     触发器实现 ...

  10. 解决 There are no resources that can be added or removed from the server

    网上下载了一个项目,在eclipse中部署时,加载项目到tomcat中项目名称无法显示,报出There are no resources that can be added or removed fr ...