HDU - 5087 Revenge of LIS II
来源:互联网 发布:下载风行网络电影 编辑:程序博客网 时间:2024/06/06 04:06
在LIS的O(n^2)的递推过程中,用一个mark[ i ]标记以arr[ i ]结尾的最长上升子序列的长度是否有多条路径推得。
#include <iostream>#include <cstdio>#include <cstdlib>#include <cstring>using namespace std;int arr[1011], mark[1011], d[1011];int n;int main(){ int T; cin>>T; while(T--) { cin>>n; for(int i=0; i<n; i++) cin>>arr[i]; memset(mark, 0, sizeof(mark)); for(int i=0; i<n; i++) { d[i]=1; for(int j=0; j<i; j++) if(arr[i]>arr[j]) { if(d[i]==d[j]+1) mark[i]=2; else if(d[i]<d[j]+1) { d[i]=d[j]+1; mark[i]=mark[j]; } } } int maxlen=0; for(int i=0; i<n; i++) maxlen=max(maxlen, d[i]); int times=0, num; for(int i=0; i<n; i++) if(d[i]==maxlen) { times++; num=i; } if(times>=2 || (times==1 && mark[num]>=2)) printf("%d\n", maxlen); else printf("%d\n", maxlen-1); } return 0;}
0 0
- Revenge of LIS II (hdu 5087 LIS)
- hdu 5087 Revenge of LIS II(LIS)
- hdu 5087 Revenge of LIS II dp
- 【DP】 HDU 5087 Revenge of LIS II
- HDU - 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II
- Revenge of LIS II(HDU 5087)
- HDU 5087 Revenge of LIS II
- hdu 5087 Revenge of LIS II ( LIS ,第二长子序列)
- hdu 5087 Revenge of LIS II(LIS,思路)
- HDU 5087 Revenge of LIS II(次长上升子序列)
- hdu 5087 Revenge of LIS II(BestCoder Round #16)
- hdu 5087 Revenge of LIS II lcs变形
- HDU 5078 Revenge of LIS II(dp LIS)
- HDOJ 5087 Revenge of LIS II DP
- HDOJ-5087-Revenge of LIS II
- HDU5087 Revenge of LIS II
- DPM 训练 之一
- sysbench的用法
- jquery简单的tab切换特效插件jquery-tab demo代码下载
- MYSQL SELECT
- ScriptManager控件
- HDU - 5087 Revenge of LIS II
- 写在前面(自废武功,从头开始)
- 答读者问(23):一个研三学生有关工作之前的学习的疑问及答复
- CH Round #57 - Story of the OI Class 查错
- Hexo 入门指南(六) - sitemap、rss 和部署
- Tweetable Mathematical Art
- HDU - 5087
- 杂谈:HTML 5页面可视性API
- IELTS Classification