poj3257

时间:2021-10-30 04:46:07

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. 网络第二节——AFNworking

      /** 要使用常规的AFN网络访问 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager]; ...

    2. 【2016-10-21】【坚持学习】【Day11】【&period;net 自带的三种委托】

      三种自带委托: Action Predicate Func Action: 无返回类型 Predicate 返回类型是bool类型 Func 自定义返回类型 Action:没有参数没有返回值 Acti ...

    3. 移动BI来袭我们要做哪些准备?

      (了解更多商业智能行业资讯.商业智能BI解决方案.商业智能客户案例,请访问:http://www.powerbi.com.cn/service) 随着智能手机的发展,商业智能(BI)基础架构也扩展到移 ...

    4. kali 渗透的一些笔记

      kali实战笔记 17:55 2016/7/19 by: _Silvers kali系统安装后的配置及美化安装vmwareToolstar zxvf VMwareTools-sfsfsfasfasfs ...

    5. Dijkstra 模板 最短路

      转载请注明出处:http://blog.csdn.net/u012860063?viewmode=contents ------------------------------------------ ...

    6. LC&lowbar;ALL&equals;C的含义

      在很多的shell脚本中,我们经常会看见某一句命令的前面有一句“LC_ALL=C” SAR_CMD="LC_ALL=C sar -u -b 1 5 | grep -i average &qu ...

    7. uoj&num;228&period; 基础数据结构练习题&lpar;线段树区间开方&rpar;

      题目链接:http://uoj.ac/problem/228 代码:(先开个坑在这个地方) #include<bits/stdc++.h> using namespace std; ; l ...

    8. Shell中单引号、双引号、反引号、反斜杠的区别

      1. 单引号 ( '' ) # grep Susan phonebook Susan Goldberg -- Susan Topple -- 如果我们想查找的是Susan Goldberg,不能直接使 ...

    9. MySQL的max&lowbar;user&lowbar;connections拒绝连接的一次踩雷经验

      近期线上的数据遇到一个问题,最终原因为max_user_connections和max_connections的一个bug导致,具体过程如下 现象 前端页面不断的出现错误页面. 排查处理过程 按照数据 ...

    10. uname查看系统名称

      功能说明:uname用来获取电脑和操作系统的相关信息. 语 法:uname [-amnrsvpio][--help][--version] 补充说明:uname可显示linux主机所用的操作系统的版本 ...

    相关文章