【NOIP2017提高A组模拟9.7】陶陶摘苹果
Description
Input
Output
Sample Input
10 5 110 3
100 200 150 140 129 134 167 198 200 111
0 30
20 40
90 100
100 110
50 60
Sample Output
7
Data Constraint
题解
考试的时候已经打出了正解,但-1放错位置,爆零
容易想到DP
设f[i][j]为第i个凳子,选了j个的最大摘苹果数
用前缀和维护区间采摘的苹果数
把凳子按l排序
转移:f[i][j]=max(f[k][j-1]+(max(a[i].l-1,a[k].r)~a[i].r)) (a[k].r<a[i].r)
max(a[l].l-1,a[k].r)是取选取苹果区间的左端点,a[i].r就是右端点
时间复杂度O(k*m^2)
code
#include<cstdio>
#include<cctype>
#include<cstdlib>
#include<algorithm>
#define R register
using namespace std;
const int N=1e6+10;
struct node{
int l,r;
}a[N];
int sum[N]