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

--------------------------------------------------------------------------------

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
 
#define rep( i , n ) for( int i = 0 ; i < n ; i++ )
#define clr( x , c ) memset( x , c , sizeof( x ) )
 
using namespace std;
 
const int maxn = 10000 + 5;
 
struct data {
int l , r;
void Read() {
scanf( "%d%d" , &l , &r );
r += l - 1;
}
bool operator < ( const data &rhs ) const {
return r < rhs.r;
}
};
  
data A[ maxn ];
 
int dp[ maxn ];
int main() {
// freopen( "test.in" , "r" , stdin );
int n;
cin >> n;
rep( i , n )
   A[ i ].Read();
   
sort( A , A + n );
   
rep( i , n ) {
dp[ i ] =1;
rep( j , i ) if( A[ j ].r < A[ i ].l )
   
   dp[ i ] = max( dp[ i ] , dp[ j ] + 1 );
   
}
int ans = 0;
rep( i , n ) 
   ans = max( ans , dp[ i ] );
cout << ans << "\n";
return 0;
}

--------------------------------------------------------------------------------

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

Time Limit: 5 Sec  Memory Limit: 64 MB
Submit: 262  Solved: 190
[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

INPUT DETAILS:

Graphic picture of the schedule:
11111111112
12345678901234567890---------这个是时间轴.
--------------------
111111 2222223333344
55555555 777777 666

这个图中1代表第一个节日从1开始,持续6个时间,直到6.

Sample Output

4

OUTPUT DETAILS:

FJ can do no better than to attend events 1, 2, 3, and 4.

HINT

Source

BZOJ 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝( dp )的更多相关文章

  1. bzoj 1664: [Usaco2006 Open]County Fair Events 参加节日庆祝【dp+树状数组】

    把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max, ...

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

    1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 255  S ...

  3. 【BZOJ】1664: [Usaco2006 Open]County Fair Events 参加节日庆祝(线段树+dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1664 和之前的那题一样啊.. 只不过权值变为了1.. 同样用线段树维护区间,然后在区间范围内dp. ...

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

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

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

    Description Farmer John has returned to the County Fair so he can attend the special events (concert ...

  6. 【动态规划】bzoj1664 [Usaco2006 Open]County Fair Events 参加节日庆祝

    将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #incl ...

  7. County Fair Events

    先按照结束时间进行排序,取第一个节日的结束时间作为当前时间,然后从第二个节日开始搜索,如果下一个节日的开始时间大于当前的时间,那么就参加这个节日,并更新当前时间 #include <bits/s ...

  8. bzoj 1652: [Usaco2006 Feb]Treats for the Cows【区间dp】

    裸的区间dp,设f[i][j]为区间(i,j)的答案,转移是f[i][j]=max(f[i+1][j]+a[i](n-j+i),f[i][j-1]+a[j]*(n-j+i)); #include< ...

  9. bzoj 1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛【dp+树状数组+hash】

    最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #in ...

随机推荐

  1. 三种尺寸:手机SIM卡使用指南

    毫无疑问目前卖的最火的手机非iPhone 5s莫属,相信仍有不少网友目前处于观望之中,由于iPhone 5s和iPhone 5c采用与iPhone相同的Nano-SIM卡,因此不少新用户在使用之前也徒 ...

  2. 【转】android权限列表

    访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permiss ...

  3. mysql 函数执行权限

    mysql> show grants for query_all@'115.236.1x0.x'; +---------------------------------------------- ...

  4. CATransition类动画

    - (void)leftClick { [UIView beginAnimations:nil context:nil]; //display mode, slow at beginning and  ...

  5. Sencha Touch 2 结合HTML5的本地存储创建数据库实现增、删、改、查

    大家好!我是范范.本人刚接触ST2到现在刚刚两个月,6月1号接的项目,那时才知道有Sencha Touch2这个东西,到现在两个月了期间的幸酸就不说了.今天说说在项目中用到的HTML5的本地存储.可能 ...

  6. ArrayList和LinkedList的各项操作性能比较

          如果用java编写程序,我们通常存储易变的数据集合时用到的数据结构往往是ArrayList,不过,在JDK中还存在另一个结构--LinkedList,只不过我们通常不用,原因在于性能问题, ...

  7. 我的Hook学习笔记

    关于Hook 一.基本概念: 钩子(Hook),是Windows消息处理机制的一个平台,应用程序能够在上面设置子程以监视指定窗体的某种消息,并且所监视的窗体能够是其它进程所创建的.当消息到达后,在目标 ...

  8. paip.数据库发邮件通知配置

    paip.数据库发邮件通知配置 作者Attilax ,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blog.csdn.net/attilax ...

  9. 关于js封装框架类库之事件模块

    在触发DOM上的某个事件时,会产生一个事件对象event.这个对象中包含着所有与事件有关的信息.包括导致事件的元素,事件的类型以及其他与特定事件相关的信息. 例如: 鼠标操作点击事件时,事件对象中会获 ...

  10. objective-C学习笔记(九)ARC

    ARC叫自动引用计数Automatic Reference Counting.针对堆上的对象,管理对象的创建和释放. 哪些对象受ARC管理: OC对象指针 Block指针 使用_attribute_( ...