JZOJ 2020.10.6 【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

题解
题目大意
一条线上有\(n\)个点,有\(m\)条线段,最多选\(k\)条线段使得覆盖的点最多
分析
考虑\(DP\)
设\(f[i][j]\)表示到了第\(i\)条线段,已经选了\(j\)条,当前这个必选的最多点数
转移
枚举一个\(k\)表示上一条线段
\(f[i][j]=max(f[k][j-1]+新的点数)\)
新的点数可以用前缀和维护
总结
没有想出DP式子
在设状态的时候可以想想要求什么,什么是变量
然后用变量来设状态
Code
#include<bits/stdc++.h>
using namespace std;
struct node
{
int begin,end;
}c[205];
int n,m,h,k,x,mx,ans,a[1000005],f[205][205];
int read()
{
int res=0;char ch=getchar();
while (ch<'0'||ch>'9') ch=getchar();
while (ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch-'0'),ch=getchar();
return res;
}
bool cmp(node x,node y)
{
return x.end<y.end;
}
int main()
{
freopen("apple.in","r",stdin);
freopen("apple.out","w",stdout);
n=read();m=read();h=read();k=read();
for (int i=1;i<=n;++i)
{
x=read();x-=h;
if (x<0) continue;
++a[x];
}
for (int i=1;i<=1000000;++i)
a[i]+=a[i-1];
for (int i=1;i<=m;++i)
c[i].begin=read(),c[i].end=read();
sort(c+1,c+1+m,cmp);
f[1][1]=a[c[1].end]-a[max(0,c[1].begin-1)];
ans=f[1][1];
for (int i=2;i<=m;++i)
{
f[i][1]=a[c[i].end]-a[max(0,c[i].begin-1)];
ans=max(ans,f[i][1]);
for (int j=2;j<=min(i,k);++j)
{
for (int k=1;k<i;++k)
f[i][j]=max(f[i][j],f[k][j-1]+a[c[i].end]-a[max(c[k].end+1,c[i].begin)-1]);
ans=max(ans,f[i][j]);
}
}
printf("%d\n",ans);
fclose(stdin);
fclose(stdout);
return 0;
}
JZOJ 2020.10.6 【NOIP2017提高A组模拟9.7】陶陶摘苹果的更多相关文章
- JZOJ 【NOIP2017提高A组模拟9.14】捕老鼠
JZOJ [NOIP2017提高A组模拟9.14]捕老鼠 题目 Description 为了加快社会主义现代化,建设新农村,农夫约(Farmer Jo)决定给农庄里的仓库灭灭鼠.于是,猫被农夫约派去捕 ...
- JZOJ 5328. 【NOIP2017提高A组模拟8.22】世界线
5328. [NOIP2017提高A组模拟8.22]世界线 (File IO): input:worldline.in output:worldline.out Time Limits: 1500 m ...
- JZOJ 5305. 【NOIP2017提高A组模拟8.18】C (Standard IO)
5305. [NOIP2017提高A组模拟8.18]C (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Description ...
- 【NOIP2017提高A组模拟9.7】JZOJ 计数题
[NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ...
- JZOJ 100029. 【NOIP2017提高A组模拟7.8】陪审团
100029. [NOIP2017提高A组模拟7.8]陪审团 Time Limits: 1000 ms Memory Limits: 131072 KB Detailed Limits Got ...
- JZOJ 5329. 【NOIP2017提高A组模拟8.22】时间机器
5329. [NOIP2017提高A组模拟8.22]时间机器 (File IO): input:machine.in output:machine.out Time Limits: 2000 ms M ...
- JZOJ 5307. 【NOIP2017提高A组模拟8.18】偷窃 (Standard IO)
5307. [NOIP2017提高A组模拟8.18]偷窃 (Standard IO) Time Limits: 1000 ms Memory Limits: 262144 KB Description ...
- JZOJ 5286. 【NOIP2017提高A组模拟8.16】花花的森林 (Standard IO)
5286. [NOIP2017提高A组模拟8.16]花花的森林 (Standard IO) Time Limits: 1000 ms Memory Limits: 131072 KB Descript ...
- 【NOIP2017提高A组模拟9.17】猫
[NOIP2017提高A组模拟9.17]猫 题目 Description 信息组最近猫成灾了! 隔壁物理组也拿猫没办法. 信息组组长只好去请神刀手来帮他们消灭猫.信息组现在共有n 只猫(n 为正整数) ...
随机推荐
- final,static,this,super 关键字总结
一.final 关键字 final关键字主要用在三个地方:变量.方法.类. 1.对于一个final变量,如果是基本数据类型的变量,则其数值一旦在初始化之后便不能更改:如果是引用类型的变量,则在对其初始 ...
- yum安装出现被锁定的报错
问题:在使用#yum install XXX 命令的时候,出现yum.pid 已被锁定的提示,无法进行yum 安装 解决: 使用# rm -f /var/run/yum.pid 命令删除该进程即可
- python00
# Python* [什么是 Python 生成器?](#什么是-Python-生成器)* [什么是 Python 迭代器?](#什么是-Python-迭代器)* [list 和 tuple 有什么区 ...
- php xml转数组
<?php libxml_disable_entity_loader(true); $notify_values = json_decode(json_encode(simplexml_load ...
- 解决无法访问 Github
可以正常使用Google,但无法打开Github. 查阅了一些资料,发现需要在hosts文件中添加映射. 在hosts文件中加入两行 140.82.113.4 github.com 140.82.11 ...
- ip_rcv 中使用skb_share_check
/* * Main IP Receive routine. */ int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct pack ...
- 402. 移掉K位数字
给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小. 注意: num 的长度小于 10002 且 ≥ k.num 不会包含任何前导零.示例 1 : 输入: num ...
- jm8.6编解码器概述
自己在学习h264的路上,欢迎讨论交流. 前段时间研究JM出品的h264编码器,代码实在看不下去,因此换了个角度来研究诸多算法--逆向方式(解码),本系列文章记录一些遇到的东西和思考. 1. JM介绍 ...
- 老板让只懂Java基本语法的我,基于AQS实现一个锁
10 点整,我到了公司,又成为全组最后一个到的员工. 正准备刷刷手机摸摸鱼,看见老板神秘兮兮地走了过来. 老板:闪客呀,你写个工具,基于 AQS 实现一个锁,给咱们组其他开发用 我:哦好的 老板:你多 ...
- Python_面试题汇总【正在整理中...】
1.十大算法 阶乘 冒泡 1 #使用递归实现阶乘 2 3 def f(n): 4 if n ==1: 5 return 1 6 else: 7 return n*(f(n-1)) 使用递归实现阶乘 1 ...