BZOJ——1649: [Usaco2006 Dec]Cow Roller Coaster
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.
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.
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
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
选用第3条,第5条和第6条钢轨
HINT
Source
因为需要依次连接,以左端点为关键字排序,类似背包的状态转移
#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的更多相关文章
- BZOJ 1649: [Usaco2006 Dec]Cow Roller Coaster( dp )
有点类似背包 , 就是那样子搞... --------------------------------------------------------------------------------- ...
- bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster【dp】
DAG上的dp 因为本身升序就是拓扑序,所以建出图来直接从1到ndp即可,设f[i][j]为到i花费了j #include<iostream> #include<cstdio> ...
- 【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 ...
- 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 ...
- 【动态规划】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]}( ...
- Bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 深搜,bitset
1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐 Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 554 Solved: 346[ ...
- BZOJ 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐( dfs )
直接从每个奶牛所在的farm dfs , 然后算一下.. ----------------------------------------------------------------------- ...
- 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 ...
- bzoj 1648: [Usaco2006 Dec]Cow Picnic 奶牛野餐【dfs】
从每个奶牛所在草场dfs,把沿途dfs到的草场的con都+1,最后符合条件的草场就是con==k的,扫一遍统计一下即可 #include<iostream> #include<cst ...
随机推荐
- Bootstrap 网格系统(Grid System)
Bootstrap 网格系统(Grid System) Bootstrap提供了一套响应式,移动设备优先的流式网格系统,随着屏幕或视口(viewport)尺寸的增加,系统会自动分为最多12列. 什么是 ...
- CS193p Lecture 11 - UITableView, iPad
UITableView 的 dataSource 和 delegate dataSource 是一种协议,由 UITableView 实现,将 Model 的数据给到 UITableView: del ...
- mysql5.6.35源码安装记录
mysql数据库源码安装: 源码地址:wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.xx.tar.gz #安装前准备, ...
- Ubuntu sudo 出现 is not in the sudoers file解决方案
前言: 自己想额外创建一个Linux账户,但是发现新创建的用户(lgq)并不能使用sudo指令. 但是在安装系统时创建的用户(abc)是可以正常使用的. 原因是新创建的用户并没有被赋予使用sudo指令 ...
- python基础知识13-迭代器与生成器,导入模块
异常处理作业讲解 file = open('/home/pyvip/aaa.txt','w+') try: my_dict = {'name':'adb'} file.write(my_dict['a ...
- c++-string-1
解答注意: 我写的时候考虑了: 1) " my"(设置flag,为true时表示上一个是非空格字符) 2) "hello John"(最后不是空格结尾, ...
- Cocos2d-x学习资料集锦
Cocos2d-x学习资料集锦: 1.Cocos2d-x官方中文文档:https://github.com/chukong/cocos-docs/blob/master/catalog/zh.md 推 ...
- Android自动化测试Uiautomator--UiObject接口简介
UiObject可以理解为控件的对象,主要对对象进行操作.按照一定条件(UiSelector)获取UiObject对象,之后对对象进行相应的操作,如下图所示. 对于对象的操作主要有点击/长按.拖动/滑 ...
- Android开发——ThreadLocal功能介绍
个静态的监听器对象,显然是无法接受的. 2. 使用实例 //首先定义一个ThreadLocal对象,选择泛型为Boolean类型 private ThreadLocal<Boolean> ...
- PYDay1-洗剑
学习语言的阶段: 第一阶段:所有东西都是新的::一个月 第二阶段:开始懂一些::一个月 第三阶段:感觉自己是不可战胜的:第三~第四个月 第四阶段:突然感觉什么都不知道,开发是无止境的::培训阶段不会遇 ...