传送门

先按照起点 sort 一遍。

这样每一个点的只由前面的点决定。

f[i][j] 表示终点为 i,花费 j 的最优解

状态转移就是一个01背包。

——代码

 #include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> int L, N, B;
int f[][]; inline int read()
{
int x = , f = ;
char ch = getchar();
for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -;
for(; isdigit(ch); ch = getchar()) x = (x << ) + (x << ) + ch - '';
return x * f;
} struct node
{
int x, w, f, c;
}p[]; inline bool cmp(node x, node y)
{
return x.x < y.x;
} inline int max(int x, int y)
{
return x > y ? x : y;
} int main()
{
int i, j;
L = read();
N = read();
B = read();
for(i = ; i <= N; i++)
{
p[i].x = read();
p[i].w = read();
p[i].f = read();
p[i].c = read();
p[i].w += p[i].x;
}
std::sort(p + , p + N + , cmp);
memset(f, -, sizeof(f));
for(i = ; i <= B; i++) f[][i] = ;
for(i = ; i <= N; i++)
for(j = B; j >= p[i].c; j--)
if(f[p[i].x][j - p[i].c] ^ -)
f[p[i].w][j] = max(f[p[i].w][j], f[p[i].x][j - p[i].c] + p[i].f);
printf("%d\n", f[L][B]);
return ;
}

最新文章

  1. bootstrap 无限极菜单
  2. javascript判断手机旋转横屏竖屏
  3. zookeeper安装配置
  4. jQuery 遍历json数组的实现代码
  5. Java锁的种类
  6. 《iOS开发指南》要改iOS8版本了,听听您的意见?
  7. php设置和获取变量类型
  8. 循环语句之for循环
  9. GenericFactoryMethod泛型工厂模式实现简单IOC功能
  10. 做了5年的Android,我转Java后台了!
  11. BZOJ1786 [Ahoi2008]Pair 配对 动态规划 逆序对
  12. 数据库 简介 升级 SQLite 总结 MD
  13. TypeScript学习笔记(九):装饰器(Decorators)
  14. JS&amp;Jquery中的循环/遍历
  15. 每天CSS学习之top/left/right/bottom
  16. ES6学习笔记&lt;一&gt; let const class extends super
  17. Netty - 3 内存分配
  18. MFC CHotKeyCtrl控件
  19. Kafka与Flink集成
  20. JS 中 this 的用法

热门文章

  1. GG_Logs 日志类库封装使用说明
  2. BACnet开发资料与调试工具
  3. 贪心+优先队列 HDOJ 5360 Hiking
  4. 401 Binary Watch 二进制手表
  5. 构建一个.net的干货类库,以便于快速的开发 - 前言
  6. CF864D Make a Permutation!
  7. Elasticsearch--建议器
  8. 盒子模型,top和margin-top
  9. python加载不了cookirlib模块的问题
  10. 在Redux中使用插件createAction之后