博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
解题报告:hdu1257 LIS裸题
阅读量:4447 次
发布时间:2019-06-07

本文共 1447 字,大约阅读时间需要 4 分钟。

2017-09-02 17:28:44

writer:pprp

那个裸题练练手,讲解在之前的博客中提到了

代码如下:

/*@theme:hdu1257@writer:pprp@begin:17:13@end:17:26@declare:LIS的裸题,温习一下@error:注意题目中说明了是多组数据@date:2017/9/2*/#include 
using namespace std;const int maxn = 1010;int arr[maxn];int dp[maxn];int main(){ //freopen("in.txt","r",stdin); int N,Max = 0; while(cin >> N) { Max = 0; for(int i = 0 ; i < N; i++) { dp[i] = 1; cin >> arr[i]; for(int j = 0 ; j < i ; j++) { if(arr[j] < arr[i]) { dp[i] = max(dp[j]+1,dp[i]); } } Max = max(Max,dp[i]); } cout << Max << endl; } return 0;}

 

第二种不用dp的解法:

代码如下:

/*@theme:hdu1257@writer:pprp@begin:17:13@end:17:36@declare:LIS的裸题,温习一下@error:@date:2017/9/2*/#include 
using namespace std;const int maxn = 1010;int arr[maxn];int tmp[maxn];int main(){ //freopen("in.txt","r",stdin); int N,len = 0; while(cin >> N) { len = 1; cin >> arr[0]; tmp[len] = arr[0]; for(int i = 1 ; i < N ; i++) { cin >> arr[i]; if(arr[i] > tmp[len]) { len++; tmp[len] = arr[i]; } else *lower_bound(tmp,tmp+len,arr[i]) = arr[i]; } cout << len << endl; } return 0;}

 

转载于:https://www.cnblogs.com/pprp/p/7467222.html

你可能感兴趣的文章
pycharm+PyQt5+python最新开发环境配置
查看>>
走进AngularJS
查看>>
【学习笔记】 唐大仕—Java程序设计 第5讲 深入理解Java语言之5.2 多态及虚方法调用...
查看>>
轻松实现Ecshop商城多语言切换
查看>>
async & await 的前世今生(Updated)
查看>>
iOS开发:用SQLite3存储和读取数据
查看>>
webstorm上svn的安装使用
查看>>
setAdapter(adapter)空指针nullPointer 解决办法 分类: ...
查看>>
【JEECG技术文档】数据权限自定义SQL表达式用法说明
查看>>
使用 Bootstrap Typeahead 组件
查看>>
第一次玩蛇,有点紧张。
查看>>
DAO层,Service层,Controller层、View层 的分工合作
查看>>
EF不能很好的支持DDD?估计是我们搞错了!
查看>>
用户登录安全框架shiro—用户的认证和授权(一)
查看>>
提取图片的文字
查看>>
Supports BorlandIDEServices
查看>>
SVM-支持向量机算法概述
查看>>
ios开发零食
查看>>
Coursera台大机器学习技法课程笔记01-linear hard SVM
查看>>
机器学习(Machine Learning)&深度学习(Deep Learning)资料(Chapter 2)
查看>>