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

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

题意:

有N个节日,每个节日有个开始时间,及持续时间。牛想尽可能多的参加节日,问最多可以参加多少。注意牛的转移速度是极快的,不花时间,且节日必须完整参加。N≤10000,开始时刻和持续时间≤100000。

题解:

dp。设f[i]表示i时刻到最后时刻最多可以参加多少节日。则f[i]=max(f[i+1],f[range[j].r+1],j为时刻i开始的节日)。

代码:

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <cstring>
 4 #define maxn 10100
 5 #define inc(i,j,k) for(int i=j;i<=k;i++)
 6 using namespace std;
 7
 8 inline int read(){
 9     char ch=getchar(); int f=1,x=0;
10     while(ch<‘0‘||ch>‘9‘){if(ch==‘-‘)f=-1; ch=getchar();}
11     while(ch>=‘0‘&&ch<=‘9‘)x=x*10+ch-‘0‘,ch=getchar();
12     return f*x;
13 }
14 struct rg{int len,n;}; rg rgs[maxn]; int f[maxn*20],n,mx,g[maxn*20];
15 int main(){
16     n=read(); inc(i,1,n){int a=read(),b=read(); rgs[i]=(rg){b,g[a]}; g[a]=i; mx=max(mx,a);}
17     for(int i=mx;i>=1;i--){
18         f[i]=f[i+1]; for(int j=g[i];j;j=rgs[j].n)f[i]=max(f[i],f[i+rgs[j].len]+1);
19     }
20     printf("%d",f[1]); return 0;
21 }

20160730

时间: 2024-10-12 16:21:28

bzoj1664[Usaco2006 Open]County Fair Events 参加节日庆祝*的相关文章

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

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

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

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 h

bzoj1664:参加节日庆祝

1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 286  Solved: 207[Submit][Status][Discuss] Description Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, coo

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

小结:线段树 &amp; 主席树

概要: 就是用来维护区间信息,然后各种秀智商游戏. 应用: 优化dp.主席树等. 技巧及注意: size值的活用:主席树就是这样来的.支持区间加减,例题和模板:主席树,[BZOJ]1146: [CTSC2008]网络管理Network(树链剖分+线段树套平衡树+二分 / dfs序+树状数组+主席树),[BZOJ]1901: Zju2112 Dynamic Rankings(区间第k小+树状数组套可持久化线段树(主席树)) 01(就是更新和不更新等这种对立操作)情况:我们就要在各个更新的操作中明白

小结:动态规划

概要: 状态.转移:最优子结构.无后效性. 技巧及注意: dp就是纯经验+智商题 在dp方程写出来后,一定要考虑边界!不要以为转移对了就行了! 滚动数组的话一定要考虑好顺序! 下标有时候可以灵活使用!比如mod意义下的dp,倍数什么.可到达性等题目都可以这样做. 如果是线性序列的max{f[k]},k<i这种可以用线段树或bit维护成log 注意“前i”和“第i”的区别(特别对于答案更新),有时换一种就能解答出问题. 在状态加限制条件,如单调.地址等. 用下标来维护下标这个答案是否可达. 博弈论

bzoj 1664 (贪心)

[Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 487  Solved: 344[Submit][Status][Discuss] Description Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, cooking s

BZOJ1665 Usaco2006 Open The Climbing Wall

1665: [Usaco2006 Open]The Climbing Wall 攀岩 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 407  Solved: 219[Submit][Status][Discuss] Description One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip

bzoj:1665: [Usaco2006 Open]The Climbing Wall 攀岩

Description One of the most popular attractions at the county fair is the climbing wall. Bessie wants to plan her trip up the wall in advance and needs your help. The wall is 30,000 millimeters wide and H (1001 <= H <= 30,000) millimeters high and h