1664: [Usaco2006 Open]County Fair Events 参加节日庆祝

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 456  Solved: 321
[Submit][Status][Discuss]

Description

Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, cooking shows, etc.). He wants to attend as many of the N (1 <= N <= 10,000) special events as he possibly can. He's rented a bicycle so he can speed from one event to the next in absolutely no time at all (0 time units to go from one event to the next!). Given a list of the events that FJ might wish to attend, with their start times (1 <= T <= 100,000) and their durations (1 <= L <= 100,000), determine the maximum number of events that FJ can attend. FJ never leaves an event early.

有N个节日每个节日有个开始时间,及持续时间. 牛想尽可能多的参加节日,问最多可以参加多少. 注意牛的转移速度是极快的,不花时间.

Input

* Line 1: A single integer, N.

* Lines 2..N+1: Each line contains two space-separated integers, T and L, that describe an event that FJ might attend.

Output

* Line 1: A single integer that is the maximum number of events FJ can attend.

Sample Input

7
1 6
8 6
14 5
19 2
1 8
18 3
10 6

Sample Output

4

貌似像这种线段按尾排序然后DP的题已经好多道了(第7页的)

dp[i]表示前i小时能参加的最多活动数量

#include<stdio.h>
#include<algorithm>
using namespace std;
typedef struct Line
{int x, y;bool operator < (const Line &b) const{if(y<b.y)return 1;return 0;}
}Line;
Line s[10005];
int dp[200005];
int main(void)
{int n, i, p;scanf("%d", &n);for(i=1;i<=n;i++){scanf("%d%d", &s[i].x, &s[i].y);s[i].y += s[i].x-1;}sort(s+1, s+n+1);p = 1;for(i=1;i<=200000;i++){dp[i] = dp[i-1];while(s[p].y==i){dp[i] = max(dp[i], dp[s[p].x-1]+1);p++;}}printf("%d\n", dp[200000]);return 0;
}

bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(DP)相关推荐

  1. BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )

    先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开 ...

  2. [Usaco2006 Open]County Fair Events 参加节日庆祝

    原题链接https://www.lydsy.com/JudgeOnline/problem.php?id=1664 可以发现的是,如果参加了节日\(i\)之后可以参加节日\(j\),当且仅当\(i\) ...

  3. BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数(数位DP+恶心细节)

    BZOJ 1662: [Usaco2006 Nov]Round Numbers 圆环数 Time Limit: 5 Sec  Memory Limit: 64 MB Description 正如你所知 ...

  4. bzoj 1664 (贪心)

    [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 487  Solved ...

  5. bzoj 1665: [Usaco2006 Open]The Climbing Wall 攀岩(最短路)

    1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 378  Solve ...

  6. bzoj 1663: [Usaco2006 Open]赶集(最长路)

    1663: [Usaco2006 Open]赶集 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 384  Solved: 217 [Submit][St ...

  7. bzoj 1661: [Usaco2006 Nov]Big Square 巨大正方形(枚举)

    1661: [Usaco2006 Nov]Big Square 巨大正方形 Time Limit: 5 Sec  Memory Limit: 64 MB Submit: 467  Solved: 23 ...

  8. bzoj 1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 -- Tarjan

    1654: [Usaco2006 Jan]The Cow Prom 奶牛舞会 Time Limit: 5 Sec  Memory Limit: 64 MB Description The N (2 & ...

  9. BZOJ 1724: [Usaco2006 Nov]Fence Repair 切割木板

    题目 1724: [Usaco2006 Nov]Fence Repair 切割木板 Time Limit: 5 Sec  Memory Limit: 64 MB Description Farmer ...

最新文章

  1. ESC/P打印:程序控制打印机自动进退纸
  2. servlet向ajax传递list数据类型,ajax向servlet传递array数据类型
  3. (转载)DevExpress ASPxGridView 使用文档六:模板
  4. java 简单获取Excel表格内容(初学者)
  5. LINUX下载编译sqlite-jdbc的jar包
  6. 用python爬虫批量下载pdf
  7. 计算机程序编程就业,计算机编程就业
  8. 今晚直播 | 手把手带你用 Three.js 实现粒子特效,走入 3D 世界!
  9. 热敏电阻、RTD、热电偶的原理和特性
  10. PHP生成订单号算法
  11. 有关电脑的英语单词(英汉对照)
  12. 我的世界在自建的服务器中装mod,《我的世界》中国版服务器MOD添加教程
  13. 全面发展还是术业专攻?这就是答案
  14. ArcGIS导出为PDF时汉字乱码,汉字变为方框
  15. MongoDB 分片片键选择与设计
  16. Java基础——异常
  17. layuiadmin 模版渲染完成执行 lay-done 写到 controller(js业务模块文件) 首次无法执行的解决方法
  18. 机器学习实战3.3决策树项目案例02:预测隐形眼镜类型
  19. PS制作炫丽背景非主流效果
  20. 装Win7吧,免得不多久又要换系统了,Win7漂亮又好用

热门文章

  1. python怎么读取中文文件-Python3 解决读取中文文件txt编码的问题
  2. python是什么专业学的-python编程学习需要哪些基础和准备工作?
  3. python和java学哪个好-Python和Java学哪个更好?
  4. python基础教程免费下载-Python基础教程(第2版)
  5. 阿里云语音识别模型端核心技术选讲
  6. c语言写贪吃蛇什么水平_细致的C语言写贪吃蛇教程+详细思路-适合新手附源码...
  7. python导入模块中的对象_详解Python项目开发时自定义模块中对象的导入和使用
  8. java新的日期_java8你应该了解的新特性(新时间与日期API)
  9. redis java eval_【宇润日常疯测-002】Redis-eval() 到底好在哪
  10. SpringSecurity系列(三) Spring Security 表单登录