先按时间排序( 开始结束都可以 ) , 然后 dp( i ) = max( dp( i ) , dp( j ) + 1 ) ( j < i && 节日 j 结束时间在节日 i 开始时间之前 ) answer = max( dp( i ) ) ( 1 <= i <= n ) -------------------------------------------------------------------------------- #include<cstdio&g…
把长度转成右端点,按右端点排升序,f[i]=max(f[j]&&r[j]<l[i]),因为r是有序的,所以可以直接二分出能转移的区间(1,w),然后用树状数组维护区间f的max,每次转移的时候直接从树状数组上查询前缀max即可,然后把更新出来的f[i]update进树状数组 #include<iostream> #include<cstdio> #include<algorithm> using namespace std; const int N…
1664: [Usaco2006 Open]County Fair Events 参加节日庆祝 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 255  Solved: 185[Submit][Status][Discuss] Description Farmer John has returned to the County Fair so he can attend the special events (concerts, rodeos, coo…
http://www.lydsy.com/JudgeOnline/problem.php?id=1664 和之前的那题一样啊.. 只不过权值变为了1.. 同样用线段树维护区间,然后在区间范围内dp. upd:(其实权值为1的可以直接贪心....右端点来就行了... #include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream>…
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…
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…
将区间按左端点排序. f(i)=max{f(j)+1}(p[j].x+p[j].y<=p[i].x && j<i) #include<cstdio> #include<algorithm> using namespace std; int n,f[10001]; struct Point{int x,y;}p[10001]; bool operator < (const Point &a,const Point &b){return…
最长上升子序列.虽然数据可以直接n方但是另写了个nlogn的 转移:f[i]=max(f[j]+1)(a[j]<a[i]) O(n^2) #include<iostream> #include<cstdio> using namespace std; const int N=5005; int n,a[N],f[N],ans; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') { if(…
http://www.lydsy.com/JudgeOnline/problem.php?id=1901 首先还是吐槽时间,我在zoj交无限tle啊!!!!!!!!我一直以为是程序错了啊啊啊啊啊啊. bzoj提交是wa!!T_T,将数组改大就acT_T 吐槽完毕. 这题之前做过,用树套树做的,但是时间感人(http://www.cnblogs.com/iwtwiioi/p/3870597.html) 鉴于我是蒟蒻,所以我根本不会做啊!! 学习,,, 恩... 这题用树状数组来维护区间,写过树状数…
题目链接:BZOJ 洛谷 \(O(n^2)\)DP很好写,对于当前的i从之前满足条件的j中选一个最大值,\(dp[i]=d[j]+1\) for(int j=1; j<i; ++j) if(a[j]<=minv[i]&&maxv[j]<=a[i])//序列只会变换一次 dp[i]=max{dp[j]+1}; 转移要满足两个条件:\(a[j]<=minv[i]\ \&\&\ maxv[j]<=a[i]\) 一个二维偏序问题,CDQ.树套树都可以.…