【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]]=max{f[i-cost[a][begin[a]]+w[a]} 当f[i-cost[a][begin[a]]可行时

初始化f=-1

f[0][0]=0

#include <cstdio>
#include <cstring>
#include <cmath>
#include <string>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define for1(i,a,n) for(int i=(a);i<=(n);++i)
#define for2(i,a,n) for(int i=(a);i<(n);++i)
#define for3(i,a,n) for(int i=(a);i>=(n);--i)
#define for4(i,a,n) for(int i=(a);i>(n);--i)
#define CC(i,a) memset(i,a,sizeof(i))
#define read(a) a=getint()
#define print(a) printf("%d", a)
#define dbg(x) cout << #x << " = " << x << endl
#define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; }
inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; }
inline const int max(const int &a, const int &b) { return a>b?a:b; }
inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=10005, M=1005;
struct dat { int x, w, f, c; } a[N];
inline const bool cmp(const dat &a, const dat &b) { return a.x<b.x; }
int f[M][M], n, l, m;
int main() {read(l); read(n); read(m);for1(i, 1, n) read(a[i].x), read(a[i].w), read(a[i].f), read(a[i].c);sort(a+1, a+1+n, cmp);int ans=-1;CC(f, -1); f[0][0]=0;for1(i, 1, n) {int x=a[i].x, c=a[i].c, e=x+a[i].w, ff=a[i].f;for1(j, c, m) if(f[j-c][x]!=-1) f[j][e]=max(f[j][e], f[j-c][x]+ff);}for1(i, 1, m) ans=max(f[i][l], ans);print(ans);return 0;
}

 

 


 

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/401516.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Delphi工具之Image Editor

Delphi Image Editor是一个工具&#xff0c;可用它来创建并编辑位图&#xff08;.bmp&#xff09;、图标&#xff08;.ico&#xff09;和光标&#xff08;.cur&#xff09;&#xff0c;还可以用它创建资源工程&#xff0c;将多个位图、图标和光标包含到单个资源文件&#xff08…

小程序 获取当前用户城市信息(省市区)

步骤使用 wx.getLocation来获取位置授权&#xff1a;获取到设备当前的地理位置信息&#xff0c;这个信息是当前位置的经纬度使用其他第三方地图服务的API&#xff1a;获取当前位置是处于哪个国家&#xff0c;哪个城市等信息&#xff08;eg&#xff1a;腾讯地图、百度地图&#…

PYTHON_正则表达式

字符匹配方法 在编写处理字符串的程序或网页时&#xff0c;经常会有查找符合某些复杂规则的字符串的需要。正则表达式就是用于描述这些规则的工具。 通配符&#xff1a;* 元字符&#xff1a;\ ^ $ * . | ? {} [] () ^ 表示匹配字符串的开头。在…

delphi中指针的用法

大家都认为&#xff0c;C语言之所以强大&#xff0c;以及其自由性&#xff0c;很大部分体现在其灵活的指针运用上。因此&#xff0c;说指针是C语言的灵魂&#xff0c;一点都不为过。同时&#xff0c;这种说法也让很多人产生误解&#xff0c;似乎只有C语言的指针才能算指针。Bas…

小程序 获取当前用户地址及地图显示

步骤使用 wx.getLocation来获取当前位置&#xff1a; 注意;当用户取消位置获取授权之后,再次点击获取位子按钮小程序不会再提醒用户是否授权,这个时候最好自己弹出提示框让用户去设置页面开启授权设置. wx.getLocation({type: wgs84, //wgs返回 gps坐标&#xff0c; gcj02返回…

任何傅里叶级数展开和卷积可以参考一下页面

Piecewise-defined Functions http://www.sagemath.org/doc/reference/sage/functions/piecewise.html转载于:https://www.cnblogs.com/ustcSL/archive/2012/06/19/2554961.html

CSS3 box-shadow 属性

2019独角兽企业重金招聘Python工程师标准>>> 实例 向 div 元素添加 box-shadow&#xff1a; div { box-shadow: 10px 10px 5px #888888; } 亲自试一试 <!DOCTYPE html> <html> <head> <style> div { width:300px; height:100px; backgroun…

小程序 省市区县三级联动选择器(caseCade)

picker组件 <view class"section"><picker mode"region" bindchange"bindRegionChange" value"{{region}}"><view class"picker">省市区选择: {{region[0]}} {{region[1]}} {{region[2]}}</view>&…

Swagger的坑

swagger.pathPatterns如果是譬如/w/.*&#xff0c;那么如果API中以w开头的描述就会在swagger-ui中显示不出来 转载于:https://www.cnblogs.com/roostinghawk/p/6473864.html

[译]Kinect for Windows SDK开发入门(二):基础知识 上

上篇文章介绍了Kinect开发的环境配置&#xff0c;这篇文章和下一篇文章将介绍Kinect开发的基本知识&#xff0c;为深入研究Kinect for Windows SDK做好基础。 每一个Kinect应用都有一些基本元素。应用程序必须探测和发现链接到设备上的Kinect传感器。在使用这些传感器之前&…

window.open

摘要&#xff1a; 当点击某个按钮或者某个事件发生出发浏览器打开一个新的窗口&#xff0c;这种交互在我们开发的时候经常会见到&#xff0c;一般有两种方法&#xff1a; 通过a标签&#xff0c;<a href"">click</a>&#xff0c;当点击click是就会跳转页面…

小程序 开发经验

项目目录理解components自定义组件库config一个公用的数据配置images本地、上传的图片放置pagespages目录存储小程序的每个页面&#xff0c;每个页面包含四个文档.json为配置文件.wxml 为模板文件&#xff0c;相当于HTML模板.wxss 为样式文件&#xff0c;相当于HTML的CSS样式表…

设置透明色

_currenTable.backgroundColor [[UIColor blackColor] colorWithAlphaComponent:0.55]; 防止字体透明 //中文的地址处理 NSString *URLString [NSURL URLWithString:ktdemodel.img] ? ktdemodel.img : [self strUTF8Encoding:ktdemodel.img]; -(NSString *)strUTF8Encoding:…

EasyUI,二级页面内容的操作

2019独角兽企业重金招聘Python工程师标准>>> 父页面获取子页面的数据 1.若仅仅是勾选&#xff0c;则将勾选的放到map中(key&#xff0c;value)&#xff0c;key是能验证数据唯一的字段&#xff0c;value就是勾选行的rowData&#xff1b; 再将map转换成json格式的字…

动画 自制弹框上滑+渐显效果

<view class"mask {{showShare ? slidefadeUp : slidefadeDown}}" wx:if"{{showShare}}" catchtouchmove"false"> </view> /* 上滑渐显效果 */ .slidefadeUp {animation: slidefadeUp 0.5s 1 ease forwards;-webkit-animation: sli…

使用LinearLayout实现ListView,解决ListView和ScrollView滚动冲突

在项目中&#xff0c;我们常常会遇到一个ScrollView里面会嵌套ListView的情况&#xff0c;但往往你会发现&#xff0c;ListView和ScrollView的滚动时间会有冲突问题&#xff0c;造成ListView不能完全显示。虽然网上有给出解决方案&#xff0c;但事实上并不好用&#xff0c;并不…

【整理】fiddler不能监听 localhost和 127.0.0.1的问题

localhost/127.0.0.1的请求不会通过任何代理发送,fiddler也就无法截获。 解决方案 1&#xff0c;用 http://localhost. (locahost紧跟一个点号)2&#xff0c;用 http://127.0.0.1. (127.0.0.1紧跟一个点号)3&#xff0c;用 http://machinename (机器名) 4&#xff0c;将localho…

IRasterStatistics Interface

今天用自己写的程序模块生成只包含一个波段的RasterDataset&#xff0c;用ArcGIS打开正常&#xff0c;用自己的程序打开灰度显示是错误的。比如这个波段的灰度范围本来是0~100&#xff0c;程序的TOCControl里却显示的是0~255。用ArcGIS打开一次以后&#xff0c;再用自己的程序打…

Javascript 对象二(Number、String、Boolean、Array、Date、Math、RegExp)

Javascript 对象二&#xff08;Number、String、Boolean、Array、Date、Math、RegExp&#xff09;Number 数字 对象String 字符串 对象Boolean 布尔 对象Array 数组 对象Date 日期 对象Math 算数 对象RegExp 正则表达式 对象Number 数字 对象 JavaScript中 数字不分为整数类型…

javascript通用验证

//alert(test); //Validator {Require : /./,Email : /^\w([-.]\w)*\w([-.]\w)*\.\w([-.]\w)*$/,Phone : /^((\(\d{2,3}\))|(\d{3}\-))?(\(0\d{2,3}\)|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/,Mobile : /^((\(\d{2,3}\))|(\d{3}\-))?13\d{9}$/,Url : /^http:\/\/[A-Za-z0-…