dp,先将材料按以终点为关键字升序排

设f[i,j]为过山车到建到位置i在用了j元钱所得到的最大价值,然后

 var x,y,v,w:array[..] of longint;
f:array[..,..] of longint;
l,n,k,m,j,i,ans:longint; function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end; procedure swap(var a,b:longint);
var c:longint;
begin
c:=a;
a:=b;
b:=c;
end; procedure sort(l,r: longint);
var i,j,p: longint;
begin
i:=l;
j:=r;
p:=y[(l+r) div ];
repeat
while y[i]<p do inc(i);
while p<y[j] do dec(j);
if not(i>j) then
begin
swap(x[i],x[j]);
swap(y[i],y[j]);
swap(v[i],v[j]);
swap(w[i],w[j]);
inc(i);
j:=j-;
end;
until i>j;
if l<j then sort(l,j);
if i<r then sort(i,r);
end; begin
readln(l,n,m);
for i:= to n do
begin
readln(x[i],j,v[i],w[i]);
y[i]:=x[i]+j;
if y[i]>l then y[i]:=l;
end;
sort(,n);
j:=;
fillchar(f,sizeof(f),);
f[,]:=;
for i:= to l do
begin
while y[j]<=i do
begin
if y[j]=i then
begin
for k:= to m do
if (f[x[j],k]>) and (k+w[j]<=m) then
f[i,k+w[j]]:=max(f[i,k+w[j]],f[x[j],k]+v[j]);
end;
inc(j);
end;
end;
ans:=;
for j:= to m do
ans:=max(ans,f[l,j]);
writeln(ans-);
end.

容易分析复杂度为O(nm)

首尾必须相连是这题关键

poj3257的更多相关文章

随机推荐

  1. 大型网站用什么技术比较好,JSP,PHP,ASP.NET

    大型网站,我建议要考虑的问题: 首先讨论一下大型网站需要注意和考虑的问题. 数据库海量数据处理:负载量不大的情况下select.delete和update是响应很迅速的,最多加几个索引就可以搞定,但千 ...

  2. IP HELPER GetAdaptersAddresses 函数

    自己做的一些笔记,XP以及以后的系统使用: MSDN 函数:http://msdn.microsoft.com/en-US/library/windows/desktop/aa365915(v=vs. ...

  3. C语言宏定义取得两数的最大值和最小值

    /*本程序时为了验证用宏来做 * 两个数的大小比较的写法*/#include<stdio.h>#define MAX(x,y) ((x)<(y)?(y):(x))#define MI ...

  4. 网络编程Socket UDP

    图表流程 linux udp测试代码 //server.c #include <stdio.h> #include <stdlib.h> #include <errno. ...

  5. 【dapper】.net平台下的框架

    http://www.cnblogs.com/yipu/archive/2012/11/21/2780199.html Method Duration Remarks Hand coded (usin ...

  6. sql之解决数据库表的循环依赖问题

    三张数据表关系如图: 其实出现表循环依赖情况:就是 同时  ConfigCompany和 Department 也有依赖,就会报错,说有循环依赖,就会报错. 所以 这个时候的解决办法:可以改 在数据库 ...

  7. Xcode常用快捷键及代码格式刷(缩进)方法-b

    Xcode版本:4.5.1 一.总结的常用命令: 隐藏xcode command+h 退出xcode command+q 关闭窗口 command+w 关闭所有窗口 command+option+w ...

  8. poj 3013 Big Christmas Tree (最短路径Dijsktra) -- 第一次用优先队列写Dijsktra

    http://poj.org/problem?id=3013 Big Christmas Tree Time Limit: 3000MS   Memory Limit: 131072K Total S ...

  9. MapReduce工作原理图文详解 (炼数成金)

    MapReduce工作原理图文详解 1.Map-Reduce 工作机制剖析图: 1.首先,第一步,我们先编写好我们的map-reduce程序,然后在一个client 节点里面进行提交.(一般来说可以在 ...

  10. sentos 上安装vnc图形界面

    一.安装gnome图形化桌面   CentOS 6.3 64位 #yum groupinstall -y "X Window System" #yum groupinstall - ...