http://www.lydsy.com/JudgeOnline/problem.php?id=1649

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 743  Solved: 370
[Submit][Status][Discuss]

Description

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

Input

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

    第1行输入L,N,B,接下来N行,每行四个整数Xi,wi,Fi,Ci.

Output

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

Sample Input

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

Sample Output

17
选用第3条,第5条和第6条钢轨

HINT

 

Source

Silver

因为需要依次连接,以左端点为关键字排序,类似背包的状态转移

 #include <algorithm>
#include <cstring>
#include <cstdio> #define max(a,b) (a>b?a:b) inline void read(int &x)
{
x=; register char ch=getchar();
for(; ch>''||ch<''; ) ch=getchar();
for(; ch>=''&&ch<=''; ch=getchar()) x=x*+ch-'';
}
const int N();
int L,n,B,f[][],ans;
struct Node {
int l,r,v,c;
bool operator < (const Node&x) const
{
return l<x.l;
}
}a[N]; int Presist()
{
read(L),read(n),read(B);
for(int i=; i<=n; ++i)
{
read(a[i].l),read(a[i].r),
read(a[i].v),read(a[i].c);
a[i].r+=a[i].l;
}
std::sort(a+,a+n+); ans=-;
memset(f,-,sizeof(f)); f[][]=;
for(int i=; i<=n; ++i)
for(int j=a[i].c; j<=B; ++j)
if(f[a[i].l][j-a[i].c]!=-)
f[a[i].r][j]=max(f[a[i].r][j],f[a[i].l][j-a[i].c]+a[i].v);
for(int i=; i<=B; ++i) ans=max(ans,f[L][i]);
printf("%d\n",ans);
return ;
} int Aptal=Presist();
int main(int argc,char**argv){;}

BZOJ——1649: [Usaco2006 Dec]Cow Roller Coaster的更多相关文章

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

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

  2. bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster【dp】

    DAG上的dp 因为本身升序就是拓扑序,所以建出图来直接从1到ndp即可,设f[i][j]为到i花费了j #include<iostream> #include<cstdio> ...

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

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

  5. 【动态规划】bzoj1649 [Usaco2006 Dec]Cow Roller Coaster

    很像背包. 这种在一个数轴上进行操作的题常常需要对区间排序. f[i][j]表示距离到i时,花费为j时的权值之和. f[x[i]+l[i]][j+c[i]]=max{f[x[i]][j]+w[i]}( ...

  6. Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset

    1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 554  Solved: 346[ ...

  7. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )

    直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...

  8. BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐

    Description The cows are having a picnic! Each of Farmer John's K (1 <= K <= 100) cows is graz ...

  9. bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】

    从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可 #include<iostream> #include<cst ...

随机推荐

  1. tomcat BIO 、NIO 、AIO

    11.11活动当天,服务器负载过大,导致部分页面出现了不可访问的状态.那后来主管就要求调优了,下面是tomcat bio.nio.apr模式以及后来自己测试的一些性能结果. 原理方面的资料都是从网上找 ...

  2. shell脚本,awk实现每个数字加1.

    [root@localhost add]# cat file [root@localhost add]# cat file|awk '{for(i=1;i<=NF;i++){$i+=1}}1' ...

  3. iOS开发--使用OpenSSL生成私钥和公钥的方法

    最近要在新项目中使用支付宝钱包进行支付,所以要调研对接支付宝的接口,支付宝开放平台采用了RSA安全签名机制,开发者可以通过支付宝   公钥验证消息来源,同时可使用自己的私钥对信息进行加密,所以需要在本 ...

  4. Java 的访问权限

    public>protected>默认(包访问权限)>private,因为protected除了可以被同一包访问,还可以被包外的子类所访问

  5. html中注释的问题

    在修改jsp页面的时候遇到了一个有点难懂的注释,mark一下 <script> <!-- alert("js code"); //--> </scri ...

  6. 我的Python分析成长之路9

    pandas入门 统计分析是数据分析的重要组成部分,它几乎贯穿整个数据分析的流程.运用统计方法,将定量与定性结合,进行的研究活动叫做统计分析.而pandas是统计分析的重要库. 1.pandas数据结 ...

  7. stm32L011F3——串口实例

    /* STM32L0xx HAL library initialization: - Configure the Flash prefetch, Flash preread and Buffer ca ...

  8. 算法竞赛中c++一些需要注意的错误

    1. 关于精度: 取整 除法取整: (除数为正)被除数为正时系统除法为向下取整,被除数为负时系统除法为向上取整. 向上取整(被除数非负,除数为正): 一般写法(有bug): int cal(int x ...

  9. css字体文本格式 鼠标样式

    缩进 text-indent 属性规定文本块中首行文本的缩进.(允许使用负值.如果使用负值,那么首行会被缩进到左边.) length 定义固定的缩进.默认值:0.% 定义基于父元素宽度的百分比的缩进. ...

  10. PHP cannoy modify header information - headers already sent by ....

    我采用的是MVC模式的写法,代码和html分离的写法 <?php require '../mysql_connect.php'; require('../model/functions.php' ...