AcWing 1010. 拦截导弹
2024-10-08 10:42:37
//贪心加dp
#include<iostream>
using namespace std ;
const int N=;
int n;
int q[N];
int f[N];
int g[N];//存每个序列末尾的数字
int main() {
while(cin>>q[n]) n++;
int res=;
for(int i=; i<n; i++) {
f[i]=;
for(int j=; j<i; j++) {
if(q[j]>=q[i])
f[i]=max(f[i],f[j]+);
res=max(res,f[i]);
}
}
cout<<res<<endl;
int cnt=;//表示序列个数
for(int i=; i<n; i++) {
int k=;//表示已经遍历的序列的个数
while(k<cnt&&g[k]<q[i])//没有遍历完所有序列,而且序列最后小于q[i]
k++;//往后找
g[k]=q[i];//当上述循环结束的时候,要么遍历完所有数组,要么找到了小于的
if(k>=cnt) cnt++;//第一次k为0,cnt为0 所以直接 g[k]=q[i]
//因为此时k>=cnt 所以cnt++ 即有一个序列
}
cout<<cnt<<endl;
return ;
}
最新文章
- 考查SQLite 3索引对整数排序的性能影响
- oracle procedure
- jQuery waterbubble 水球图
- iOS 抽象工厂模式
- 边工作边刷题:70天一遍leetcode: day 78
- SU sufdmod2命令学习
- Excel Xll开发资料
- HTTP Digest authentication
- 解析Tensorflow官方English-Franch翻译器demo
- javascript学习初衷
- WinRarHelper帮助类
- Workbooks 对象的 Open 方法参数说明
- Oracle查询语句导致CPU使用率过高问题处理
- 自动获取svn的版本号
- ObjectArx2013新建工程出错的解决办法
- 万恶的deferred_segment_creation(延迟块分配)
- selenium基础-打开百度进行搜索
- git命令将本地代码提交到github
- The value of &#39;filter_horizontal[0]&#39; must be a many-to-many field. The value of &#39;raw_id_fields[0]&#39; must be a foreign key or a many-to-many field.
- DK NIO的BUG,例如臭名昭著的epoll bug,它会导致Selector空轮询,最终导致CPU 100%。
热门文章
- Kafka消费者没有收到通知的分析
- ES6常用语法(二)
- 搭建网页HTML结构
- BZOJ2005: [Noi2010]能量采集(欧拉函数)
- Count the Colors ZOJ - 1610 区间颜色覆盖
- hibernate报错:MappingException: Could not determine type for...解决办法
- Python带你来一次说走就走的环球旅行
- 剑指offer-面试题17-打印从1到最大的n位数-数字
- openlayers画区域
- Linux之docker搭建